
obj/user/idle:     file format elf32-i386


Disassembly of section .text:

00800020 <_start>:
// starts us running when we are initially loaded into a new environment.
.text
.globl _start
_start:
	// See if we were started with arguments on the stack
	cmpl $USTACKTOP, %esp
  800020:	81 fc 00 e0 bf ee    	cmp    $0xeebfe000,%esp
	jne args_exist
  800026:	75 04                	jne    80002c <args_exist>

	// If not, push dummy argc/argv arguments.
	// This happens when we are loaded by the kernel,
	// because the kernel does not know about passing arguments.
	pushl $0
  800028:	6a 00                	push   $0x0
	pushl $0
  80002a:	6a 00                	push   $0x0

0080002c <args_exist>:

args_exist:
	call libmain
  80002c:	e8 1b 00 00 00       	call   80004c <libmain>
1:	jmp 1b
  800031:	eb fe                	jmp    800031 <args_exist+0x5>
	...

00800034 <umain>:
#include <inc/x86.h>
#include <inc/lib.h>

void
umain(void)
{
  800034:	55                   	push   %ebp
  800035:	89 e5                	mov    %esp,%ebp
  800037:	83 ec 08             	sub    $0x8,%esp
	binaryname = "idle";
  80003a:	c7 05 00 60 80 00 00 	movl   $0x802800,0x806000
  800041:	28 80 00 
	// Instead of busy-waiting like this,
	// a better way would be to use the processor's HLT instruction
	// to cause the processor to stop executing until the next interrupt -
	// doing so allows the processor to conserve power more effectively.
	while (1) {
		sys_yield();
  800044:	e8 68 04 00 00       	call   8004b1 <sys_yield>
static __inline uint64_t read_tsc(void) __attribute__((always_inline));

static __inline void
breakpoint(void)
{
	__asm __volatile("int3");
  800049:	cc                   	int3   
  80004a:	eb f8                	jmp    800044 <umain+0x10>

0080004c <libmain>:
volatile struct Env *env;
char *binaryname = "(PROGRAM NAME UNKNOWN)";

void
libmain(int argc, char **argv)
{
  80004c:	55                   	push   %ebp
  80004d:	89 e5                	mov    %esp,%ebp
  80004f:	83 ec 18             	sub    $0x18,%esp
  800052:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  800055:	89 75 fc             	mov    %esi,-0x4(%ebp)
  800058:	8b 75 08             	mov    0x8(%ebp),%esi
  80005b:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	// set env to point at our env structure in envs[].
	// LAB 3: Your code here.
  envid_t envid   = sys_getenvid();
  80005e:	e8 82 04 00 00       	call   8004e5 <sys_getenvid>
	env = &envs [ENVX(envid)];
  800063:	25 ff 03 00 00       	and    $0x3ff,%eax
  800068:	6b c0 7c             	imul   $0x7c,%eax,%eax
  80006b:	05 00 00 c0 ee       	add    $0xeec00000,%eax
  800070:	a3 74 60 80 00       	mov    %eax,0x806074

	// save the name of the program so that panic() can use it
	if (argc > 0)
  800075:	85 f6                	test   %esi,%esi
  800077:	7e 07                	jle    800080 <libmain+0x34>
		binaryname = argv[0];
  800079:	8b 03                	mov    (%ebx),%eax
  80007b:	a3 00 60 80 00       	mov    %eax,0x806000

	// call user main routine
	umain(argc, argv);
  800080:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  800084:	89 34 24             	mov    %esi,(%esp)
  800087:	e8 a8 ff ff ff       	call   800034 <umain>

	// exit gracefully
	exit();
  80008c:	e8 0b 00 00 00       	call   80009c <exit>
}
  800091:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  800094:	8b 75 fc             	mov    -0x4(%ebp),%esi
  800097:	89 ec                	mov    %ebp,%esp
  800099:	5d                   	pop    %ebp
  80009a:	c3                   	ret    
	...

0080009c <exit>:

#include <inc/lib.h>

void
exit(void)
{
  80009c:	55                   	push   %ebp
  80009d:	89 e5                	mov    %esp,%ebp
  80009f:	83 ec 18             	sub    $0x18,%esp
	close_all();
  8000a2:	e8 12 0a 00 00       	call   800ab9 <close_all>
	sys_env_destroy(0);
  8000a7:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8000ae:	e8 66 04 00 00       	call   800519 <sys_env_destroy>
}
  8000b3:	c9                   	leave  
  8000b4:	c3                   	ret    
  8000b5:	00 00                	add    %al,(%eax)
	...

008000b8 <sys_cgetc>:
	syscall(SYS_cputs, 0, (uint32_t)s, len, 0, 0, 0);
}

int
sys_cgetc(void)
{
  8000b8:	55                   	push   %ebp
  8000b9:	89 e5                	mov    %esp,%ebp
  8000bb:	83 ec 0c             	sub    $0xc,%esp
  8000be:	89 1c 24             	mov    %ebx,(%esp)
  8000c1:	89 74 24 04          	mov    %esi,0x4(%esp)
  8000c5:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8000c9:	ba 00 00 00 00       	mov    $0x0,%edx
  8000ce:	b8 01 00 00 00       	mov    $0x1,%eax
  8000d3:	89 d1                	mov    %edx,%ecx
  8000d5:	89 d3                	mov    %edx,%ebx
  8000d7:	89 d7                	mov    %edx,%edi
  8000d9:	89 d6                	mov    %edx,%esi
  8000db:	cd 30                	int    $0x30

int
sys_cgetc(void)
{
	return syscall(SYS_cgetc, 0, 0, 0, 0, 0, 0);
}
  8000dd:	8b 1c 24             	mov    (%esp),%ebx
  8000e0:	8b 74 24 04          	mov    0x4(%esp),%esi
  8000e4:	8b 7c 24 08          	mov    0x8(%esp),%edi
  8000e8:	89 ec                	mov    %ebp,%esp
  8000ea:	5d                   	pop    %ebp
  8000eb:	c3                   	ret    

008000ec <sys_cputs>:
	return ret;
}

void
sys_cputs(const char *s, size_t len)
{
  8000ec:	55                   	push   %ebp
  8000ed:	89 e5                	mov    %esp,%ebp
  8000ef:	83 ec 0c             	sub    $0xc,%esp
  8000f2:	89 1c 24             	mov    %ebx,(%esp)
  8000f5:	89 74 24 04          	mov    %esi,0x4(%esp)
  8000f9:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8000fd:	b8 00 00 00 00       	mov    $0x0,%eax
  800102:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800105:	8b 55 08             	mov    0x8(%ebp),%edx
  800108:	89 c3                	mov    %eax,%ebx
  80010a:	89 c7                	mov    %eax,%edi
  80010c:	89 c6                	mov    %eax,%esi
  80010e:	cd 30                	int    $0x30

void
sys_cputs(const char *s, size_t len)
{
	syscall(SYS_cputs, 0, (uint32_t)s, len, 0, 0, 0);
}
  800110:	8b 1c 24             	mov    (%esp),%ebx
  800113:	8b 74 24 04          	mov    0x4(%esp),%esi
  800117:	8b 7c 24 08          	mov    0x8(%esp),%edi
  80011b:	89 ec                	mov    %ebp,%esp
  80011d:	5d                   	pop    %ebp
  80011e:	c3                   	ret    

0080011f <sys_ns_recv>:
  return syscall(SYS_ns_send, 0, (uint32_t)pkt, len, 0, 0, 0);
}

int
sys_ns_recv(void *pkt, uint32_t len)
{
  80011f:	55                   	push   %ebp
  800120:	89 e5                	mov    %esp,%ebp
  800122:	83 ec 0c             	sub    $0xc,%esp
  800125:	89 1c 24             	mov    %ebx,(%esp)
  800128:	89 74 24 04          	mov    %esi,0x4(%esp)
  80012c:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800130:	bb 00 00 00 00       	mov    $0x0,%ebx
  800135:	b8 10 00 00 00       	mov    $0x10,%eax
  80013a:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  80013d:	8b 55 08             	mov    0x8(%ebp),%edx
  800140:	89 df                	mov    %ebx,%edi
  800142:	89 de                	mov    %ebx,%esi
  800144:	cd 30                	int    $0x30

int
sys_ns_recv(void *pkt, uint32_t len)
{
  return syscall(SYS_ns_recv, 0, (uint32_t)pkt, len, 0, 0, 0);
}
  800146:	8b 1c 24             	mov    (%esp),%ebx
  800149:	8b 74 24 04          	mov    0x4(%esp),%esi
  80014d:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800151:	89 ec                	mov    %ebp,%esp
  800153:	5d                   	pop    %ebp
  800154:	c3                   	ret    

00800155 <sys_ns_send>:
	return (unsigned int) syscall(SYS_time_msec, 0, 0, 0, 0, 0, 0);
}

int
sys_ns_send(void *pkt, uint32_t len)
{
  800155:	55                   	push   %ebp
  800156:	89 e5                	mov    %esp,%ebp
  800158:	83 ec 0c             	sub    $0xc,%esp
  80015b:	89 1c 24             	mov    %ebx,(%esp)
  80015e:	89 74 24 04          	mov    %esi,0x4(%esp)
  800162:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800166:	bb 00 00 00 00       	mov    $0x0,%ebx
  80016b:	b8 0f 00 00 00       	mov    $0xf,%eax
  800170:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800173:	8b 55 08             	mov    0x8(%ebp),%edx
  800176:	89 df                	mov    %ebx,%edi
  800178:	89 de                	mov    %ebx,%esi
  80017a:	cd 30                	int    $0x30

int
sys_ns_send(void *pkt, uint32_t len)
{
  return syscall(SYS_ns_send, 0, (uint32_t)pkt, len, 0, 0, 0);
}
  80017c:	8b 1c 24             	mov    (%esp),%ebx
  80017f:	8b 74 24 04          	mov    0x4(%esp),%esi
  800183:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800187:	89 ec                	mov    %ebp,%esp
  800189:	5d                   	pop    %ebp
  80018a:	c3                   	ret    

0080018b <sys_time_msec>:
	return syscall(SYS_ipc_recv, 1, (uint32_t)dstva, 0, 0, 0, 0);
}

unsigned int
sys_time_msec(void)
{
  80018b:	55                   	push   %ebp
  80018c:	89 e5                	mov    %esp,%ebp
  80018e:	83 ec 0c             	sub    $0xc,%esp
  800191:	89 1c 24             	mov    %ebx,(%esp)
  800194:	89 74 24 04          	mov    %esi,0x4(%esp)
  800198:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  80019c:	ba 00 00 00 00       	mov    $0x0,%edx
  8001a1:	b8 0e 00 00 00       	mov    $0xe,%eax
  8001a6:	89 d1                	mov    %edx,%ecx
  8001a8:	89 d3                	mov    %edx,%ebx
  8001aa:	89 d7                	mov    %edx,%edi
  8001ac:	89 d6                	mov    %edx,%esi
  8001ae:	cd 30                	int    $0x30

unsigned int
sys_time_msec(void)
{
	return (unsigned int) syscall(SYS_time_msec, 0, 0, 0, 0, 0, 0);
}
  8001b0:	8b 1c 24             	mov    (%esp),%ebx
  8001b3:	8b 74 24 04          	mov    0x4(%esp),%esi
  8001b7:	8b 7c 24 08          	mov    0x8(%esp),%edi
  8001bb:	89 ec                	mov    %ebp,%esp
  8001bd:	5d                   	pop    %ebp
  8001be:	c3                   	ret    

008001bf <sys_ipc_recv>:
	return syscall(SYS_ipc_try_send, 1, envid, value, (uint32_t) srcva, perm, 0);
}

int
sys_ipc_recv(void *dstva)
{
  8001bf:	55                   	push   %ebp
  8001c0:	89 e5                	mov    %esp,%ebp
  8001c2:	83 ec 38             	sub    $0x38,%esp
  8001c5:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  8001c8:	89 75 f8             	mov    %esi,-0x8(%ebp)
  8001cb:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8001ce:	b9 00 00 00 00       	mov    $0x0,%ecx
  8001d3:	b8 0d 00 00 00       	mov    $0xd,%eax
  8001d8:	8b 55 08             	mov    0x8(%ebp),%edx
  8001db:	89 cb                	mov    %ecx,%ebx
  8001dd:	89 cf                	mov    %ecx,%edi
  8001df:	89 ce                	mov    %ecx,%esi
  8001e1:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  8001e3:	85 c0                	test   %eax,%eax
  8001e5:	7e 28                	jle    80020f <sys_ipc_recv+0x50>
		panic("syscall %d returned %d (> 0)", num, ret);
  8001e7:	89 44 24 10          	mov    %eax,0x10(%esp)
  8001eb:	c7 44 24 0c 0d 00 00 	movl   $0xd,0xc(%esp)
  8001f2:	00 
  8001f3:	c7 44 24 08 1c 28 80 	movl   $0x80281c,0x8(%esp)
  8001fa:	00 
  8001fb:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800202:	00 
  800203:	c7 04 24 39 28 80 00 	movl   $0x802839,(%esp)
  80020a:	e8 05 17 00 00       	call   801914 <_panic>

int
sys_ipc_recv(void *dstva)
{
	return syscall(SYS_ipc_recv, 1, (uint32_t)dstva, 0, 0, 0, 0);
}
  80020f:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800212:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800215:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800218:	89 ec                	mov    %ebp,%esp
  80021a:	5d                   	pop    %ebp
  80021b:	c3                   	ret    

0080021c <sys_ipc_try_send>:
	return syscall(SYS_env_set_pgfault_upcall, 1, envid, (uint32_t) upcall, 0, 0, 0);
}

int
sys_ipc_try_send(envid_t envid, uint32_t value, void *srcva, int perm)
{
  80021c:	55                   	push   %ebp
  80021d:	89 e5                	mov    %esp,%ebp
  80021f:	83 ec 38             	sub    $0x38,%esp
  800222:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800225:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800228:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  80022b:	be 00 00 00 00       	mov    $0x0,%esi
  800230:	b8 0c 00 00 00       	mov    $0xc,%eax
  800235:	8b 7d 14             	mov    0x14(%ebp),%edi
  800238:	8b 5d 10             	mov    0x10(%ebp),%ebx
  80023b:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  80023e:	8b 55 08             	mov    0x8(%ebp),%edx
  800241:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800243:	85 c0                	test   %eax,%eax
  800245:	7e 28                	jle    80026f <sys_ipc_try_send+0x53>
		panic("syscall %d returned %d (> 0)", num, ret);
  800247:	89 44 24 10          	mov    %eax,0x10(%esp)
  80024b:	c7 44 24 0c 0c 00 00 	movl   $0xc,0xc(%esp)
  800252:	00 
  800253:	c7 44 24 08 1c 28 80 	movl   $0x80281c,0x8(%esp)
  80025a:	00 
  80025b:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800262:	00 
  800263:	c7 04 24 39 28 80 00 	movl   $0x802839,(%esp)
  80026a:	e8 a5 16 00 00       	call   801914 <_panic>

int
sys_ipc_try_send(envid_t envid, uint32_t value, void *srcva, int perm)
{
	return syscall(SYS_ipc_try_send, 1, envid, value, (uint32_t) srcva, perm, 0);
}
  80026f:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800272:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800275:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800278:	89 ec                	mov    %ebp,%esp
  80027a:	5d                   	pop    %ebp
  80027b:	c3                   	ret    

0080027c <sys_env_set_pgfault_upcall>:
	return syscall(SYS_env_set_trapframe, 1, envid, (uint32_t) tf, 0, 0, 0);
}

int
sys_env_set_pgfault_upcall(envid_t envid, void *upcall)
{
  80027c:	55                   	push   %ebp
  80027d:	89 e5                	mov    %esp,%ebp
  80027f:	83 ec 38             	sub    $0x38,%esp
  800282:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800285:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800288:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  80028b:	bb 00 00 00 00       	mov    $0x0,%ebx
  800290:	b8 0a 00 00 00       	mov    $0xa,%eax
  800295:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800298:	8b 55 08             	mov    0x8(%ebp),%edx
  80029b:	89 df                	mov    %ebx,%edi
  80029d:	89 de                	mov    %ebx,%esi
  80029f:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  8002a1:	85 c0                	test   %eax,%eax
  8002a3:	7e 28                	jle    8002cd <sys_env_set_pgfault_upcall+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  8002a5:	89 44 24 10          	mov    %eax,0x10(%esp)
  8002a9:	c7 44 24 0c 0a 00 00 	movl   $0xa,0xc(%esp)
  8002b0:	00 
  8002b1:	c7 44 24 08 1c 28 80 	movl   $0x80281c,0x8(%esp)
  8002b8:	00 
  8002b9:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  8002c0:	00 
  8002c1:	c7 04 24 39 28 80 00 	movl   $0x802839,(%esp)
  8002c8:	e8 47 16 00 00       	call   801914 <_panic>

int
sys_env_set_pgfault_upcall(envid_t envid, void *upcall)
{
	return syscall(SYS_env_set_pgfault_upcall, 1, envid, (uint32_t) upcall, 0, 0, 0);
}
  8002cd:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  8002d0:	8b 75 f8             	mov    -0x8(%ebp),%esi
  8002d3:	8b 7d fc             	mov    -0x4(%ebp),%edi
  8002d6:	89 ec                	mov    %ebp,%esp
  8002d8:	5d                   	pop    %ebp
  8002d9:	c3                   	ret    

008002da <sys_env_set_trapframe>:
	return syscall(SYS_env_set_status, 1, envid, status, 0, 0, 0);
}

int
sys_env_set_trapframe(envid_t envid, struct Trapframe *tf)
{
  8002da:	55                   	push   %ebp
  8002db:	89 e5                	mov    %esp,%ebp
  8002dd:	83 ec 38             	sub    $0x38,%esp
  8002e0:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  8002e3:	89 75 f8             	mov    %esi,-0x8(%ebp)
  8002e6:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8002e9:	bb 00 00 00 00       	mov    $0x0,%ebx
  8002ee:	b8 09 00 00 00       	mov    $0x9,%eax
  8002f3:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  8002f6:	8b 55 08             	mov    0x8(%ebp),%edx
  8002f9:	89 df                	mov    %ebx,%edi
  8002fb:	89 de                	mov    %ebx,%esi
  8002fd:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  8002ff:	85 c0                	test   %eax,%eax
  800301:	7e 28                	jle    80032b <sys_env_set_trapframe+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  800303:	89 44 24 10          	mov    %eax,0x10(%esp)
  800307:	c7 44 24 0c 09 00 00 	movl   $0x9,0xc(%esp)
  80030e:	00 
  80030f:	c7 44 24 08 1c 28 80 	movl   $0x80281c,0x8(%esp)
  800316:	00 
  800317:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  80031e:	00 
  80031f:	c7 04 24 39 28 80 00 	movl   $0x802839,(%esp)
  800326:	e8 e9 15 00 00       	call   801914 <_panic>

int
sys_env_set_trapframe(envid_t envid, struct Trapframe *tf)
{
	return syscall(SYS_env_set_trapframe, 1, envid, (uint32_t) tf, 0, 0, 0);
}
  80032b:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  80032e:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800331:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800334:	89 ec                	mov    %ebp,%esp
  800336:	5d                   	pop    %ebp
  800337:	c3                   	ret    

00800338 <sys_env_set_status>:

// sys_exofork is inlined in lib.h

int
sys_env_set_status(envid_t envid, int status)
{
  800338:	55                   	push   %ebp
  800339:	89 e5                	mov    %esp,%ebp
  80033b:	83 ec 38             	sub    $0x38,%esp
  80033e:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800341:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800344:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800347:	bb 00 00 00 00       	mov    $0x0,%ebx
  80034c:	b8 08 00 00 00       	mov    $0x8,%eax
  800351:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800354:	8b 55 08             	mov    0x8(%ebp),%edx
  800357:	89 df                	mov    %ebx,%edi
  800359:	89 de                	mov    %ebx,%esi
  80035b:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  80035d:	85 c0                	test   %eax,%eax
  80035f:	7e 28                	jle    800389 <sys_env_set_status+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  800361:	89 44 24 10          	mov    %eax,0x10(%esp)
  800365:	c7 44 24 0c 08 00 00 	movl   $0x8,0xc(%esp)
  80036c:	00 
  80036d:	c7 44 24 08 1c 28 80 	movl   $0x80281c,0x8(%esp)
  800374:	00 
  800375:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  80037c:	00 
  80037d:	c7 04 24 39 28 80 00 	movl   $0x802839,(%esp)
  800384:	e8 8b 15 00 00       	call   801914 <_panic>

int
sys_env_set_status(envid_t envid, int status)
{
	return syscall(SYS_env_set_status, 1, envid, status, 0, 0, 0);
}
  800389:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  80038c:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80038f:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800392:	89 ec                	mov    %ebp,%esp
  800394:	5d                   	pop    %ebp
  800395:	c3                   	ret    

00800396 <sys_page_unmap>:
	return syscall(SYS_page_map, 1, srcenv, (uint32_t) srcva, dstenv, (uint32_t) dstva, perm);
}

int
sys_page_unmap(envid_t envid, void *va)
{
  800396:	55                   	push   %ebp
  800397:	89 e5                	mov    %esp,%ebp
  800399:	83 ec 38             	sub    $0x38,%esp
  80039c:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  80039f:	89 75 f8             	mov    %esi,-0x8(%ebp)
  8003a2:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8003a5:	bb 00 00 00 00       	mov    $0x0,%ebx
  8003aa:	b8 06 00 00 00       	mov    $0x6,%eax
  8003af:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  8003b2:	8b 55 08             	mov    0x8(%ebp),%edx
  8003b5:	89 df                	mov    %ebx,%edi
  8003b7:	89 de                	mov    %ebx,%esi
  8003b9:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  8003bb:	85 c0                	test   %eax,%eax
  8003bd:	7e 28                	jle    8003e7 <sys_page_unmap+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  8003bf:	89 44 24 10          	mov    %eax,0x10(%esp)
  8003c3:	c7 44 24 0c 06 00 00 	movl   $0x6,0xc(%esp)
  8003ca:	00 
  8003cb:	c7 44 24 08 1c 28 80 	movl   $0x80281c,0x8(%esp)
  8003d2:	00 
  8003d3:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  8003da:	00 
  8003db:	c7 04 24 39 28 80 00 	movl   $0x802839,(%esp)
  8003e2:	e8 2d 15 00 00       	call   801914 <_panic>

int
sys_page_unmap(envid_t envid, void *va)
{
	return syscall(SYS_page_unmap, 1, envid, (uint32_t) va, 0, 0, 0);
}
  8003e7:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  8003ea:	8b 75 f8             	mov    -0x8(%ebp),%esi
  8003ed:	8b 7d fc             	mov    -0x4(%ebp),%edi
  8003f0:	89 ec                	mov    %ebp,%esp
  8003f2:	5d                   	pop    %ebp
  8003f3:	c3                   	ret    

008003f4 <sys_page_map>:
	return syscall(SYS_page_alloc, 1, envid, (uint32_t) va, perm, 0, 0);
}

int
sys_page_map(envid_t srcenv, void *srcva, envid_t dstenv, void *dstva, int perm)
{
  8003f4:	55                   	push   %ebp
  8003f5:	89 e5                	mov    %esp,%ebp
  8003f7:	83 ec 38             	sub    $0x38,%esp
  8003fa:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  8003fd:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800400:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800403:	b8 05 00 00 00       	mov    $0x5,%eax
  800408:	8b 75 18             	mov    0x18(%ebp),%esi
  80040b:	8b 7d 14             	mov    0x14(%ebp),%edi
  80040e:	8b 5d 10             	mov    0x10(%ebp),%ebx
  800411:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800414:	8b 55 08             	mov    0x8(%ebp),%edx
  800417:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800419:	85 c0                	test   %eax,%eax
  80041b:	7e 28                	jle    800445 <sys_page_map+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  80041d:	89 44 24 10          	mov    %eax,0x10(%esp)
  800421:	c7 44 24 0c 05 00 00 	movl   $0x5,0xc(%esp)
  800428:	00 
  800429:	c7 44 24 08 1c 28 80 	movl   $0x80281c,0x8(%esp)
  800430:	00 
  800431:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800438:	00 
  800439:	c7 04 24 39 28 80 00 	movl   $0x802839,(%esp)
  800440:	e8 cf 14 00 00       	call   801914 <_panic>

int
sys_page_map(envid_t srcenv, void *srcva, envid_t dstenv, void *dstva, int perm)
{
	return syscall(SYS_page_map, 1, srcenv, (uint32_t) srcva, dstenv, (uint32_t) dstva, perm);
}
  800445:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800448:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80044b:	8b 7d fc             	mov    -0x4(%ebp),%edi
  80044e:	89 ec                	mov    %ebp,%esp
  800450:	5d                   	pop    %ebp
  800451:	c3                   	ret    

00800452 <sys_page_alloc>:
	syscall(SYS_yield, 0, 0, 0, 0, 0, 0);
}

int
sys_page_alloc(envid_t envid, void *va, int perm)
{
  800452:	55                   	push   %ebp
  800453:	89 e5                	mov    %esp,%ebp
  800455:	83 ec 38             	sub    $0x38,%esp
  800458:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  80045b:	89 75 f8             	mov    %esi,-0x8(%ebp)
  80045e:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800461:	be 00 00 00 00       	mov    $0x0,%esi
  800466:	b8 04 00 00 00       	mov    $0x4,%eax
  80046b:	8b 5d 10             	mov    0x10(%ebp),%ebx
  80046e:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800471:	8b 55 08             	mov    0x8(%ebp),%edx
  800474:	89 f7                	mov    %esi,%edi
  800476:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800478:	85 c0                	test   %eax,%eax
  80047a:	7e 28                	jle    8004a4 <sys_page_alloc+0x52>
		panic("syscall %d returned %d (> 0)", num, ret);
  80047c:	89 44 24 10          	mov    %eax,0x10(%esp)
  800480:	c7 44 24 0c 04 00 00 	movl   $0x4,0xc(%esp)
  800487:	00 
  800488:	c7 44 24 08 1c 28 80 	movl   $0x80281c,0x8(%esp)
  80048f:	00 
  800490:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800497:	00 
  800498:	c7 04 24 39 28 80 00 	movl   $0x802839,(%esp)
  80049f:	e8 70 14 00 00       	call   801914 <_panic>

int
sys_page_alloc(envid_t envid, void *va, int perm)
{
	return syscall(SYS_page_alloc, 1, envid, (uint32_t) va, perm, 0, 0);
}
  8004a4:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  8004a7:	8b 75 f8             	mov    -0x8(%ebp),%esi
  8004aa:	8b 7d fc             	mov    -0x4(%ebp),%edi
  8004ad:	89 ec                	mov    %ebp,%esp
  8004af:	5d                   	pop    %ebp
  8004b0:	c3                   	ret    

008004b1 <sys_yield>:
	 return syscall(SYS_getenvid, 0, 0, 0, 0, 0, 0);
}

void
sys_yield(void)
{
  8004b1:	55                   	push   %ebp
  8004b2:	89 e5                	mov    %esp,%ebp
  8004b4:	83 ec 0c             	sub    $0xc,%esp
  8004b7:	89 1c 24             	mov    %ebx,(%esp)
  8004ba:	89 74 24 04          	mov    %esi,0x4(%esp)
  8004be:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8004c2:	ba 00 00 00 00       	mov    $0x0,%edx
  8004c7:	b8 0b 00 00 00       	mov    $0xb,%eax
  8004cc:	89 d1                	mov    %edx,%ecx
  8004ce:	89 d3                	mov    %edx,%ebx
  8004d0:	89 d7                	mov    %edx,%edi
  8004d2:	89 d6                	mov    %edx,%esi
  8004d4:	cd 30                	int    $0x30

void
sys_yield(void)
{
	syscall(SYS_yield, 0, 0, 0, 0, 0, 0);
}
  8004d6:	8b 1c 24             	mov    (%esp),%ebx
  8004d9:	8b 74 24 04          	mov    0x4(%esp),%esi
  8004dd:	8b 7c 24 08          	mov    0x8(%esp),%edi
  8004e1:	89 ec                	mov    %ebp,%esp
  8004e3:	5d                   	pop    %ebp
  8004e4:	c3                   	ret    

008004e5 <sys_getenvid>:
	return syscall(SYS_env_destroy, 1, envid, 0, 0, 0, 0);
}

envid_t
sys_getenvid(void)
{
  8004e5:	55                   	push   %ebp
  8004e6:	89 e5                	mov    %esp,%ebp
  8004e8:	83 ec 0c             	sub    $0xc,%esp
  8004eb:	89 1c 24             	mov    %ebx,(%esp)
  8004ee:	89 74 24 04          	mov    %esi,0x4(%esp)
  8004f2:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8004f6:	ba 00 00 00 00       	mov    $0x0,%edx
  8004fb:	b8 02 00 00 00       	mov    $0x2,%eax
  800500:	89 d1                	mov    %edx,%ecx
  800502:	89 d3                	mov    %edx,%ebx
  800504:	89 d7                	mov    %edx,%edi
  800506:	89 d6                	mov    %edx,%esi
  800508:	cd 30                	int    $0x30

envid_t
sys_getenvid(void)
{
	 return syscall(SYS_getenvid, 0, 0, 0, 0, 0, 0);
}
  80050a:	8b 1c 24             	mov    (%esp),%ebx
  80050d:	8b 74 24 04          	mov    0x4(%esp),%esi
  800511:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800515:	89 ec                	mov    %ebp,%esp
  800517:	5d                   	pop    %ebp
  800518:	c3                   	ret    

00800519 <sys_env_destroy>:
	return syscall(SYS_cgetc, 0, 0, 0, 0, 0, 0);
}

int
sys_env_destroy(envid_t envid)
{
  800519:	55                   	push   %ebp
  80051a:	89 e5                	mov    %esp,%ebp
  80051c:	83 ec 38             	sub    $0x38,%esp
  80051f:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800522:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800525:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800528:	b9 00 00 00 00       	mov    $0x0,%ecx
  80052d:	b8 03 00 00 00       	mov    $0x3,%eax
  800532:	8b 55 08             	mov    0x8(%ebp),%edx
  800535:	89 cb                	mov    %ecx,%ebx
  800537:	89 cf                	mov    %ecx,%edi
  800539:	89 ce                	mov    %ecx,%esi
  80053b:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  80053d:	85 c0                	test   %eax,%eax
  80053f:	7e 28                	jle    800569 <sys_env_destroy+0x50>
		panic("syscall %d returned %d (> 0)", num, ret);
  800541:	89 44 24 10          	mov    %eax,0x10(%esp)
  800545:	c7 44 24 0c 03 00 00 	movl   $0x3,0xc(%esp)
  80054c:	00 
  80054d:	c7 44 24 08 1c 28 80 	movl   $0x80281c,0x8(%esp)
  800554:	00 
  800555:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  80055c:	00 
  80055d:	c7 04 24 39 28 80 00 	movl   $0x802839,(%esp)
  800564:	e8 ab 13 00 00       	call   801914 <_panic>

int
sys_env_destroy(envid_t envid)
{
	return syscall(SYS_env_destroy, 1, envid, 0, 0, 0, 0);
}
  800569:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  80056c:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80056f:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800572:	89 ec                	mov    %ebp,%esp
  800574:	5d                   	pop    %ebp
  800575:	c3                   	ret    
	...

00800580 <fd2num>:
// File descriptor manipulators
// --------------------------------------------------------------

int
fd2num(struct Fd *fd)
{
  800580:	55                   	push   %ebp
  800581:	89 e5                	mov    %esp,%ebp
  800583:	8b 45 08             	mov    0x8(%ebp),%eax
  800586:	05 00 00 00 30       	add    $0x30000000,%eax
  80058b:	c1 e8 0c             	shr    $0xc,%eax
	return ((uintptr_t) fd - FDTABLE) / PGSIZE;
}
  80058e:	5d                   	pop    %ebp
  80058f:	c3                   	ret    

00800590 <fd2data>:

char*
fd2data(struct Fd *fd)
{
  800590:	55                   	push   %ebp
  800591:	89 e5                	mov    %esp,%ebp
  800593:	83 ec 04             	sub    $0x4,%esp
	return INDEX2DATA(fd2num(fd));
  800596:	8b 45 08             	mov    0x8(%ebp),%eax
  800599:	89 04 24             	mov    %eax,(%esp)
  80059c:	e8 df ff ff ff       	call   800580 <fd2num>
  8005a1:	05 20 00 0d 00       	add    $0xd0020,%eax
  8005a6:	c1 e0 0c             	shl    $0xc,%eax
}
  8005a9:	c9                   	leave  
  8005aa:	c3                   	ret    

008005ab <fd_alloc>:
// Returns 0 on success, < 0 on error.  Errors are:
//	-E_MAX_FD: no more file descriptors
// On error, *fd_store is set to 0.
int
fd_alloc(struct Fd **fd_store)
{
  8005ab:	55                   	push   %ebp
  8005ac:	89 e5                	mov    %esp,%ebp
  8005ae:	57                   	push   %edi
  8005af:	56                   	push   %esi
  8005b0:	53                   	push   %ebx
  8005b1:	8b 7d 08             	mov    0x8(%ebp),%edi
	int i;
	struct Fd *fd;

	for (i = 0; i < MAXFD; i++) {
		fd = INDEX2FD(i);
		if ((vpd[PDX(fd)] & PTE_P) == 0 || (vpt[VPN(fd)] & PTE_P) == 0) {
  8005b4:	a1 00 dd 7b ef       	mov    0xef7bdd00,%eax
  8005b9:	a8 01                	test   $0x1,%al
  8005bb:	74 36                	je     8005f3 <fd_alloc+0x48>
  8005bd:	a1 00 00 74 ef       	mov    0xef740000,%eax
  8005c2:	a8 01                	test   $0x1,%al
  8005c4:	74 2d                	je     8005f3 <fd_alloc+0x48>
  8005c6:	b8 00 10 00 d0       	mov    $0xd0001000,%eax
  8005cb:	b9 00 d0 7b ef       	mov    $0xef7bd000,%ecx
  8005d0:	be 00 00 40 ef       	mov    $0xef400000,%esi
  8005d5:	89 c3                	mov    %eax,%ebx
  8005d7:	89 c2                	mov    %eax,%edx
  8005d9:	c1 ea 16             	shr    $0x16,%edx
  8005dc:	8b 14 91             	mov    (%ecx,%edx,4),%edx
  8005df:	f6 c2 01             	test   $0x1,%dl
  8005e2:	74 14                	je     8005f8 <fd_alloc+0x4d>
  8005e4:	89 c2                	mov    %eax,%edx
  8005e6:	c1 ea 0c             	shr    $0xc,%edx
  8005e9:	8b 14 96             	mov    (%esi,%edx,4),%edx
  8005ec:	f6 c2 01             	test   $0x1,%dl
  8005ef:	75 10                	jne    800601 <fd_alloc+0x56>
  8005f1:	eb 05                	jmp    8005f8 <fd_alloc+0x4d>
  8005f3:	bb 00 00 00 d0       	mov    $0xd0000000,%ebx
			*fd_store = fd;
  8005f8:	89 1f                	mov    %ebx,(%edi)
  8005fa:	b8 00 00 00 00       	mov    $0x0,%eax
			return 0;
  8005ff:	eb 17                	jmp    800618 <fd_alloc+0x6d>
  800601:	05 00 10 00 00       	add    $0x1000,%eax
fd_alloc(struct Fd **fd_store)
{
	int i;
	struct Fd *fd;

	for (i = 0; i < MAXFD; i++) {
  800606:	3d 00 00 02 d0       	cmp    $0xd0020000,%eax
  80060b:	75 c8                	jne    8005d5 <fd_alloc+0x2a>
		if ((vpd[PDX(fd)] & PTE_P) == 0 || (vpt[VPN(fd)] & PTE_P) == 0) {
			*fd_store = fd;
			return 0;
		}
	}
	*fd_store = 0;
  80060d:	c7 07 00 00 00 00    	movl   $0x0,(%edi)
  800613:	b8 f6 ff ff ff       	mov    $0xfffffff6,%eax
	return -E_MAX_OPEN;
}
  800618:	5b                   	pop    %ebx
  800619:	5e                   	pop    %esi
  80061a:	5f                   	pop    %edi
  80061b:	5d                   	pop    %ebp
  80061c:	c3                   	ret    

0080061d <fd_lookup>:
// Returns 0 on success (the page is in range and mapped), < 0 on error.
// Errors are:
//	-E_INVAL: fdnum was either not in range or not mapped.
int
fd_lookup(int fdnum, struct Fd **fd_store)
{
  80061d:	55                   	push   %ebp
  80061e:	89 e5                	mov    %esp,%ebp
	struct Fd *fd=NULL;

	if (fdnum < 0 || fdnum >= MAXFD) {
  800620:	8b 45 08             	mov    0x8(%ebp),%eax
  800623:	83 f8 1f             	cmp    $0x1f,%eax
  800626:	77 36                	ja     80065e <fd_lookup+0x41>
		if (debug)
			cprintf("[%08x] bad fd %d\n", env->env_id, fd);
		return -E_INVAL;
	}
	fd = INDEX2FD(fdnum);
  800628:	05 00 00 0d 00       	add    $0xd0000,%eax
  80062d:	c1 e0 0c             	shl    $0xc,%eax
	if (!(vpd[PDX(fd)] & PTE_P) || !(vpt[VPN(fd)] & PTE_P)) {
  800630:	89 c2                	mov    %eax,%edx
  800632:	c1 ea 16             	shr    $0x16,%edx
  800635:	8b 14 95 00 d0 7b ef 	mov    -0x10843000(,%edx,4),%edx
  80063c:	f6 c2 01             	test   $0x1,%dl
  80063f:	74 1d                	je     80065e <fd_lookup+0x41>
  800641:	89 c2                	mov    %eax,%edx
  800643:	c1 ea 0c             	shr    $0xc,%edx
  800646:	8b 14 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%edx
  80064d:	f6 c2 01             	test   $0x1,%dl
  800650:	74 0c                	je     80065e <fd_lookup+0x41>
		if (debug)
			cprintf("[%08x] closed fd %d\n", env->env_id, fd);
		return -E_INVAL;
	}
	*fd_store = fd;
  800652:	8b 55 0c             	mov    0xc(%ebp),%edx
  800655:	89 02                	mov    %eax,(%edx)
  800657:	b8 00 00 00 00       	mov    $0x0,%eax
	return 0;
  80065c:	eb 05                	jmp    800663 <fd_lookup+0x46>
  80065e:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
}
  800663:	5d                   	pop    %ebp
  800664:	c3                   	ret    

00800665 <seek>:
	return (*dev->dev_write)(fd, buf, n);
}

int
seek(int fdnum, off_t offset)
{
  800665:	55                   	push   %ebp
  800666:	89 e5                	mov    %esp,%ebp
  800668:	83 ec 18             	sub    $0x18,%esp
	int r;
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0)
  80066b:	8d 45 fc             	lea    -0x4(%ebp),%eax
  80066e:	89 44 24 04          	mov    %eax,0x4(%esp)
  800672:	8b 45 08             	mov    0x8(%ebp),%eax
  800675:	89 04 24             	mov    %eax,(%esp)
  800678:	e8 a0 ff ff ff       	call   80061d <fd_lookup>
  80067d:	85 c0                	test   %eax,%eax
  80067f:	78 0e                	js     80068f <seek+0x2a>
		return r;
	fd->fd_offset = offset;
  800681:	8b 45 fc             	mov    -0x4(%ebp),%eax
  800684:	8b 55 0c             	mov    0xc(%ebp),%edx
  800687:	89 50 04             	mov    %edx,0x4(%eax)
  80068a:	b8 00 00 00 00       	mov    $0x0,%eax
	return 0;
}
  80068f:	c9                   	leave  
  800690:	c3                   	ret    

00800691 <dev_lookup>:
	0
};

int
dev_lookup(int dev_id, struct Dev **dev)
{
  800691:	55                   	push   %ebp
  800692:	89 e5                	mov    %esp,%ebp
  800694:	56                   	push   %esi
  800695:	53                   	push   %ebx
  800696:	83 ec 10             	sub    $0x10,%esp
  800699:	8b 4d 08             	mov    0x8(%ebp),%ecx
  80069c:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	int i;
	for (i = 0; devtab[i]; i++)
		if (devtab[i]->dev_id == dev_id) {
			*dev = devtab[i];
			return 0;
  80069f:	ba 00 00 00 00       	mov    $0x0,%edx
int
dev_lookup(int dev_id, struct Dev **dev)
{
	int i;
	for (i = 0; devtab[i]; i++)
		if (devtab[i]->dev_id == dev_id) {
  8006a4:	b8 04 60 80 00       	mov    $0x806004,%eax
  8006a9:	39 0d 04 60 80 00    	cmp    %ecx,0x806004
  8006af:	75 11                	jne    8006c2 <dev_lookup+0x31>
  8006b1:	eb 04                	jmp    8006b7 <dev_lookup+0x26>
  8006b3:	39 08                	cmp    %ecx,(%eax)
  8006b5:	75 10                	jne    8006c7 <dev_lookup+0x36>
			*dev = devtab[i];
  8006b7:	89 03                	mov    %eax,(%ebx)
  8006b9:	b8 00 00 00 00       	mov    $0x0,%eax
			return 0;
  8006be:	66 90                	xchg   %ax,%ax
  8006c0:	eb 36                	jmp    8006f8 <dev_lookup+0x67>

int
dev_lookup(int dev_id, struct Dev **dev)
{
	int i;
	for (i = 0; devtab[i]; i++)
  8006c2:	be c4 28 80 00       	mov    $0x8028c4,%esi
  8006c7:	83 c2 01             	add    $0x1,%edx
  8006ca:	8b 04 96             	mov    (%esi,%edx,4),%eax
  8006cd:	85 c0                	test   %eax,%eax
  8006cf:	75 e2                	jne    8006b3 <dev_lookup+0x22>
		if (devtab[i]->dev_id == dev_id) {
			*dev = devtab[i];
			return 0;
		}
	cprintf("[%08x] unknown device type %d\n", env->env_id, dev_id);
  8006d1:	a1 74 60 80 00       	mov    0x806074,%eax
  8006d6:	8b 40 4c             	mov    0x4c(%eax),%eax
  8006d9:	89 4c 24 08          	mov    %ecx,0x8(%esp)
  8006dd:	89 44 24 04          	mov    %eax,0x4(%esp)
  8006e1:	c7 04 24 48 28 80 00 	movl   $0x802848,(%esp)
  8006e8:	e8 ec 12 00 00       	call   8019d9 <cprintf>
	*dev = 0;
  8006ed:	c7 03 00 00 00 00    	movl   $0x0,(%ebx)
  8006f3:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
	return -E_INVAL;
}
  8006f8:	83 c4 10             	add    $0x10,%esp
  8006fb:	5b                   	pop    %ebx
  8006fc:	5e                   	pop    %esi
  8006fd:	5d                   	pop    %ebp
  8006fe:	c3                   	ret    

008006ff <fstat>:
	return (*dev->dev_trunc)(fd, newsize);
}

int
fstat(int fdnum, struct Stat *stat)
{
  8006ff:	55                   	push   %ebp
  800700:	89 e5                	mov    %esp,%ebp
  800702:	53                   	push   %ebx
  800703:	83 ec 24             	sub    $0x24,%esp
  800706:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  800709:	8d 45 f0             	lea    -0x10(%ebp),%eax
  80070c:	89 44 24 04          	mov    %eax,0x4(%esp)
  800710:	8b 45 08             	mov    0x8(%ebp),%eax
  800713:	89 04 24             	mov    %eax,(%esp)
  800716:	e8 02 ff ff ff       	call   80061d <fd_lookup>
  80071b:	85 c0                	test   %eax,%eax
  80071d:	78 53                	js     800772 <fstat+0x73>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  80071f:	8d 45 f4             	lea    -0xc(%ebp),%eax
  800722:	89 44 24 04          	mov    %eax,0x4(%esp)
  800726:	8b 45 f0             	mov    -0x10(%ebp),%eax
  800729:	8b 00                	mov    (%eax),%eax
  80072b:	89 04 24             	mov    %eax,(%esp)
  80072e:	e8 5e ff ff ff       	call   800691 <dev_lookup>
{
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  800733:	85 c0                	test   %eax,%eax
  800735:	78 3b                	js     800772 <fstat+0x73>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if (!dev->dev_stat)
  800737:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  80073c:	8b 55 f4             	mov    -0xc(%ebp),%edx
  80073f:	83 7a 14 00          	cmpl   $0x0,0x14(%edx)
  800743:	74 2d                	je     800772 <fstat+0x73>
		return -E_NOT_SUPP;
	stat->st_name[0] = 0;
  800745:	c6 03 00             	movb   $0x0,(%ebx)
	stat->st_size = 0;
  800748:	c7 83 80 00 00 00 00 	movl   $0x0,0x80(%ebx)
  80074f:	00 00 00 
	stat->st_isdir = 0;
  800752:	c7 83 84 00 00 00 00 	movl   $0x0,0x84(%ebx)
  800759:	00 00 00 
	stat->st_dev = dev;
  80075c:	8b 45 f4             	mov    -0xc(%ebp),%eax
  80075f:	89 83 88 00 00 00    	mov    %eax,0x88(%ebx)
	return (*dev->dev_stat)(fd, stat);
  800765:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  800769:	8b 55 f0             	mov    -0x10(%ebp),%edx
  80076c:	89 14 24             	mov    %edx,(%esp)
  80076f:	ff 50 14             	call   *0x14(%eax)
}
  800772:	83 c4 24             	add    $0x24,%esp
  800775:	5b                   	pop    %ebx
  800776:	5d                   	pop    %ebp
  800777:	c3                   	ret    

00800778 <ftruncate>:
	return 0;
}

int
ftruncate(int fdnum, off_t newsize)
{
  800778:	55                   	push   %ebp
  800779:	89 e5                	mov    %esp,%ebp
  80077b:	53                   	push   %ebx
  80077c:	83 ec 24             	sub    $0x24,%esp
  80077f:	8b 5d 08             	mov    0x8(%ebp),%ebx
	int r;
	struct Dev *dev;
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0
  800782:	8d 45 f0             	lea    -0x10(%ebp),%eax
  800785:	89 44 24 04          	mov    %eax,0x4(%esp)
  800789:	89 1c 24             	mov    %ebx,(%esp)
  80078c:	e8 8c fe ff ff       	call   80061d <fd_lookup>
  800791:	85 c0                	test   %eax,%eax
  800793:	78 5f                	js     8007f4 <ftruncate+0x7c>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  800795:	8d 45 f4             	lea    -0xc(%ebp),%eax
  800798:	89 44 24 04          	mov    %eax,0x4(%esp)
  80079c:	8b 45 f0             	mov    -0x10(%ebp),%eax
  80079f:	8b 00                	mov    (%eax),%eax
  8007a1:	89 04 24             	mov    %eax,(%esp)
  8007a4:	e8 e8 fe ff ff       	call   800691 <dev_lookup>
ftruncate(int fdnum, off_t newsize)
{
	int r;
	struct Dev *dev;
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0
  8007a9:	85 c0                	test   %eax,%eax
  8007ab:	78 47                	js     8007f4 <ftruncate+0x7c>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_RDONLY) {
  8007ad:	8b 55 f0             	mov    -0x10(%ebp),%edx
  8007b0:	f6 42 08 03          	testb  $0x3,0x8(%edx)
  8007b4:	75 23                	jne    8007d9 <ftruncate+0x61>
		cprintf("[%08x] ftruncate %d -- bad mode\n",
			env->env_id, fdnum); 
  8007b6:	a1 74 60 80 00       	mov    0x806074,%eax
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_RDONLY) {
		cprintf("[%08x] ftruncate %d -- bad mode\n",
  8007bb:	8b 40 4c             	mov    0x4c(%eax),%eax
  8007be:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8007c2:	89 44 24 04          	mov    %eax,0x4(%esp)
  8007c6:	c7 04 24 68 28 80 00 	movl   $0x802868,(%esp)
  8007cd:	e8 07 12 00 00       	call   8019d9 <cprintf>
  8007d2:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
			env->env_id, fdnum); 
		return -E_INVAL;
  8007d7:	eb 1b                	jmp    8007f4 <ftruncate+0x7c>
	}
	if (!dev->dev_trunc)
  8007d9:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8007dc:	8b 48 18             	mov    0x18(%eax),%ecx
  8007df:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  8007e4:	85 c9                	test   %ecx,%ecx
  8007e6:	74 0c                	je     8007f4 <ftruncate+0x7c>
		return -E_NOT_SUPP;
	return (*dev->dev_trunc)(fd, newsize);
  8007e8:	8b 45 0c             	mov    0xc(%ebp),%eax
  8007eb:	89 44 24 04          	mov    %eax,0x4(%esp)
  8007ef:	89 14 24             	mov    %edx,(%esp)
  8007f2:	ff d1                	call   *%ecx
}
  8007f4:	83 c4 24             	add    $0x24,%esp
  8007f7:	5b                   	pop    %ebx
  8007f8:	5d                   	pop    %ebp
  8007f9:	c3                   	ret    

008007fa <write>:
	return tot;
}

ssize_t
write(int fdnum, const void *buf, size_t n)
{
  8007fa:	55                   	push   %ebp
  8007fb:	89 e5                	mov    %esp,%ebp
  8007fd:	53                   	push   %ebx
  8007fe:	83 ec 24             	sub    $0x24,%esp
  800801:	8b 5d 08             	mov    0x8(%ebp),%ebx
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  800804:	8d 45 f0             	lea    -0x10(%ebp),%eax
  800807:	89 44 24 04          	mov    %eax,0x4(%esp)
  80080b:	89 1c 24             	mov    %ebx,(%esp)
  80080e:	e8 0a fe ff ff       	call   80061d <fd_lookup>
  800813:	85 c0                	test   %eax,%eax
  800815:	78 66                	js     80087d <write+0x83>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  800817:	8d 45 f4             	lea    -0xc(%ebp),%eax
  80081a:	89 44 24 04          	mov    %eax,0x4(%esp)
  80081e:	8b 45 f0             	mov    -0x10(%ebp),%eax
  800821:	8b 00                	mov    (%eax),%eax
  800823:	89 04 24             	mov    %eax,(%esp)
  800826:	e8 66 fe ff ff       	call   800691 <dev_lookup>
{
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  80082b:	85 c0                	test   %eax,%eax
  80082d:	78 4e                	js     80087d <write+0x83>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_RDONLY) {
  80082f:	8b 55 f0             	mov    -0x10(%ebp),%edx
  800832:	f6 42 08 03          	testb  $0x3,0x8(%edx)
  800836:	75 23                	jne    80085b <write+0x61>
		cprintf("[%08x] write %d -- bad mode\n", env->env_id, fdnum);
  800838:	a1 74 60 80 00       	mov    0x806074,%eax
  80083d:	8b 40 4c             	mov    0x4c(%eax),%eax
  800840:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  800844:	89 44 24 04          	mov    %eax,0x4(%esp)
  800848:	c7 04 24 89 28 80 00 	movl   $0x802889,(%esp)
  80084f:	e8 85 11 00 00       	call   8019d9 <cprintf>
  800854:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
		return -E_INVAL;
  800859:	eb 22                	jmp    80087d <write+0x83>
	}
	if (debug)
		cprintf("write %d %p %d via dev %s\n",
			fdnum, buf, n, dev->dev_name);
	if (!dev->dev_write)
  80085b:	8b 45 f4             	mov    -0xc(%ebp),%eax
  80085e:	8b 48 0c             	mov    0xc(%eax),%ecx
  800861:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  800866:	85 c9                	test   %ecx,%ecx
  800868:	74 13                	je     80087d <write+0x83>
		return -E_NOT_SUPP;
	return (*dev->dev_write)(fd, buf, n);
  80086a:	8b 45 10             	mov    0x10(%ebp),%eax
  80086d:	89 44 24 08          	mov    %eax,0x8(%esp)
  800871:	8b 45 0c             	mov    0xc(%ebp),%eax
  800874:	89 44 24 04          	mov    %eax,0x4(%esp)
  800878:	89 14 24             	mov    %edx,(%esp)
  80087b:	ff d1                	call   *%ecx
}
  80087d:	83 c4 24             	add    $0x24,%esp
  800880:	5b                   	pop    %ebx
  800881:	5d                   	pop    %ebp
  800882:	c3                   	ret    

00800883 <read>:
	return r;
}

ssize_t
read(int fdnum, void *buf, size_t n)
{
  800883:	55                   	push   %ebp
  800884:	89 e5                	mov    %esp,%ebp
  800886:	57                   	push   %edi
  800887:	56                   	push   %esi
  800888:	53                   	push   %ebx
  800889:	83 ec 2c             	sub    $0x2c,%esp
  80088c:	8b 5d 08             	mov    0x8(%ebp),%ebx
  80088f:	8b 75 10             	mov    0x10(%ebp),%esi
	int r;
	int m, tot;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  800892:	8d 45 e0             	lea    -0x20(%ebp),%eax
  800895:	89 44 24 04          	mov    %eax,0x4(%esp)
  800899:	89 1c 24             	mov    %ebx,(%esp)
  80089c:	e8 7c fd ff ff       	call   80061d <fd_lookup>
  8008a1:	85 c0                	test   %eax,%eax
  8008a3:	0f 88 b0 00 00 00    	js     800959 <read+0xd6>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  8008a9:	8d 45 e4             	lea    -0x1c(%ebp),%eax
  8008ac:	89 44 24 04          	mov    %eax,0x4(%esp)
  8008b0:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8008b3:	8b 00                	mov    (%eax),%eax
  8008b5:	89 04 24             	mov    %eax,(%esp)
  8008b8:	e8 d4 fd ff ff       	call   800691 <dev_lookup>
	int r;
	int m, tot;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  8008bd:	85 c0                	test   %eax,%eax
  8008bf:	0f 88 94 00 00 00    	js     800959 <read+0xd6>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_WRONLY) {
  8008c5:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8008c8:	8b 40 08             	mov    0x8(%eax),%eax
  8008cb:	83 e0 03             	and    $0x3,%eax
  8008ce:	83 f8 01             	cmp    $0x1,%eax
  8008d1:	75 23                	jne    8008f6 <read+0x73>
		cprintf("[%08x] read %d -- bad mode\n", env->env_id, fdnum); 
  8008d3:	a1 74 60 80 00       	mov    0x806074,%eax
  8008d8:	8b 40 4c             	mov    0x4c(%eax),%eax
  8008db:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8008df:	89 44 24 04          	mov    %eax,0x4(%esp)
  8008e3:	c7 04 24 a6 28 80 00 	movl   $0x8028a6,(%esp)
  8008ea:	e8 ea 10 00 00       	call   8019d9 <cprintf>
  8008ef:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
		return -E_INVAL;
  8008f4:	eb 63                	jmp    800959 <read+0xd6>
	}
	if (!dev->dev_read)
  8008f6:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  8008fb:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  8008fe:	83 7a 08 00          	cmpl   $0x0,0x8(%edx)
  800902:	74 55                	je     800959 <read+0xd6>
		return -E_NOT_SUPP;

  for (tot = 0; tot < n; tot += m) {
  800904:	ba 00 00 00 00       	mov    $0x0,%edx
  800909:	bb 00 00 00 00       	mov    $0x0,%ebx
  80090e:	b8 00 00 00 00       	mov    $0x0,%eax
  800913:	85 f6                	test   %esi,%esi
  800915:	74 42                	je     800959 <read+0xd6>
    int count=0;
    if ((n-tot)/PGSIZE == 0)
  800917:	bf 00 10 00 00       	mov    $0x1000,%edi
  80091c:	89 f0                	mov    %esi,%eax
  80091e:	29 d0                	sub    %edx,%eax
  800920:	89 c1                	mov    %eax,%ecx
  800922:	81 e1 ff 0f 00 00    	and    $0xfff,%ecx
  800928:	3d 00 10 00 00       	cmp    $0x1000,%eax
  80092d:	0f 43 cf             	cmovae %edi,%ecx
      count = (n-tot)%PGSIZE;
    else
      count = PGSIZE;

	  m = (*dev->dev_read)(fd, (char *)buf + tot, count);
  800930:	89 4c 24 08          	mov    %ecx,0x8(%esp)
  800934:	03 55 0c             	add    0xc(%ebp),%edx
  800937:	89 54 24 04          	mov    %edx,0x4(%esp)
  80093b:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80093e:	89 04 24             	mov    %eax,(%esp)
  800941:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  800944:	ff 50 08             	call   *0x8(%eax)
		if (m < 0)
  800947:	85 c0                	test   %eax,%eax
  800949:	78 0e                	js     800959 <read+0xd6>
			return m;
		if (m == 0)
  80094b:	85 c0                	test   %eax,%eax
  80094d:	74 08                	je     800957 <read+0xd4>
		return -E_INVAL;
	}
	if (!dev->dev_read)
		return -E_NOT_SUPP;

  for (tot = 0; tot < n; tot += m) {
  80094f:	01 c3                	add    %eax,%ebx
  800951:	89 da                	mov    %ebx,%edx
  800953:	39 f3                	cmp    %esi,%ebx
  800955:	72 c5                	jb     80091c <read+0x99>
  800957:	89 d8                	mov    %ebx,%eax
			return m;
		if (m == 0)
			break;
	}
	return tot;
}
  800959:	83 c4 2c             	add    $0x2c,%esp
  80095c:	5b                   	pop    %ebx
  80095d:	5e                   	pop    %esi
  80095e:	5f                   	pop    %edi
  80095f:	5d                   	pop    %ebp
  800960:	c3                   	ret    

00800961 <readn>:

ssize_t
readn(int fdnum, void *buf, size_t n)
{
  800961:	55                   	push   %ebp
  800962:	89 e5                	mov    %esp,%ebp
  800964:	57                   	push   %edi
  800965:	56                   	push   %esi
  800966:	53                   	push   %ebx
  800967:	83 ec 1c             	sub    $0x1c,%esp
  80096a:	8b 7d 08             	mov    0x8(%ebp),%edi
  80096d:	8b 75 10             	mov    0x10(%ebp),%esi
	int m, tot;
  struct Fd *fd = INDEX2FD(fdnum);

	for (tot = 0; tot < n; tot += m) {
  800970:	ba 00 00 00 00       	mov    $0x0,%edx
  800975:	bb 00 00 00 00       	mov    $0x0,%ebx
  80097a:	b8 00 00 00 00       	mov    $0x0,%eax
  80097f:	85 f6                	test   %esi,%esi
  800981:	74 29                	je     8009ac <readn+0x4b>
		m = read(fdnum, (char*)buf + tot, n - tot);
  800983:	89 f0                	mov    %esi,%eax
  800985:	29 d0                	sub    %edx,%eax
  800987:	89 44 24 08          	mov    %eax,0x8(%esp)
  80098b:	03 55 0c             	add    0xc(%ebp),%edx
  80098e:	89 54 24 04          	mov    %edx,0x4(%esp)
  800992:	89 3c 24             	mov    %edi,(%esp)
  800995:	e8 e9 fe ff ff       	call   800883 <read>
		if (m < 0)
  80099a:	85 c0                	test   %eax,%eax
  80099c:	78 0e                	js     8009ac <readn+0x4b>
			return m;
		if (m == 0)
  80099e:	85 c0                	test   %eax,%eax
  8009a0:	74 08                	je     8009aa <readn+0x49>
readn(int fdnum, void *buf, size_t n)
{
	int m, tot;
  struct Fd *fd = INDEX2FD(fdnum);

	for (tot = 0; tot < n; tot += m) {
  8009a2:	01 c3                	add    %eax,%ebx
  8009a4:	89 da                	mov    %ebx,%edx
  8009a6:	39 f3                	cmp    %esi,%ebx
  8009a8:	72 d9                	jb     800983 <readn+0x22>
  8009aa:	89 d8                	mov    %ebx,%eax
			return m;
		if (m == 0)
			break;
	}
	return tot;
}
  8009ac:	83 c4 1c             	add    $0x1c,%esp
  8009af:	5b                   	pop    %ebx
  8009b0:	5e                   	pop    %esi
  8009b1:	5f                   	pop    %edi
  8009b2:	5d                   	pop    %ebp
  8009b3:	c3                   	ret    

008009b4 <fd_close>:
// If 'must_exist' is 1, then fd_close returns -E_INVAL when passed a
// closed or nonexistent file descriptor.
// Returns 0 on success, < 0 on error.
int
fd_close(struct Fd *fd, bool must_exist)
{
  8009b4:	55                   	push   %ebp
  8009b5:	89 e5                	mov    %esp,%ebp
  8009b7:	83 ec 28             	sub    $0x28,%esp
  8009ba:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  8009bd:	89 75 fc             	mov    %esi,-0x4(%ebp)
  8009c0:	8b 75 08             	mov    0x8(%ebp),%esi
	struct Fd *fd2;
	struct Dev *dev;
	int r;
	if ((r = fd_lookup(fd2num(fd), &fd2)) < 0
  8009c3:	89 34 24             	mov    %esi,(%esp)
  8009c6:	e8 b5 fb ff ff       	call   800580 <fd2num>
  8009cb:	8d 55 f4             	lea    -0xc(%ebp),%edx
  8009ce:	89 54 24 04          	mov    %edx,0x4(%esp)
  8009d2:	89 04 24             	mov    %eax,(%esp)
  8009d5:	e8 43 fc ff ff       	call   80061d <fd_lookup>
  8009da:	89 c3                	mov    %eax,%ebx
  8009dc:	85 c0                	test   %eax,%eax
  8009de:	78 05                	js     8009e5 <fd_close+0x31>
  8009e0:	3b 75 f4             	cmp    -0xc(%ebp),%esi
  8009e3:	74 0e                	je     8009f3 <fd_close+0x3f>
	    || fd != fd2)
		return (must_exist ? r : 0);
  8009e5:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
  8009e9:	b8 00 00 00 00       	mov    $0x0,%eax
  8009ee:	0f 44 d8             	cmove  %eax,%ebx
  8009f1:	eb 3d                	jmp    800a30 <fd_close+0x7c>
	if ((r = dev_lookup(fd->fd_dev_id, &dev)) >= 0) {
  8009f3:	8d 45 f0             	lea    -0x10(%ebp),%eax
  8009f6:	89 44 24 04          	mov    %eax,0x4(%esp)
  8009fa:	8b 06                	mov    (%esi),%eax
  8009fc:	89 04 24             	mov    %eax,(%esp)
  8009ff:	e8 8d fc ff ff       	call   800691 <dev_lookup>
  800a04:	89 c3                	mov    %eax,%ebx
  800a06:	85 c0                	test   %eax,%eax
  800a08:	78 16                	js     800a20 <fd_close+0x6c>
		if (dev->dev_close)
  800a0a:	8b 45 f0             	mov    -0x10(%ebp),%eax
  800a0d:	8b 40 10             	mov    0x10(%eax),%eax
  800a10:	bb 00 00 00 00       	mov    $0x0,%ebx
  800a15:	85 c0                	test   %eax,%eax
  800a17:	74 07                	je     800a20 <fd_close+0x6c>
			r = (*dev->dev_close)(fd);
  800a19:	89 34 24             	mov    %esi,(%esp)
  800a1c:	ff d0                	call   *%eax
  800a1e:	89 c3                	mov    %eax,%ebx
		else
			r = 0;
	}
	// Make sure fd is unmapped.  Might be a no-op if
	// (*dev->dev_close)(fd) already unmapped it.
	(void) sys_page_unmap(0, fd);
  800a20:	89 74 24 04          	mov    %esi,0x4(%esp)
  800a24:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  800a2b:	e8 66 f9 ff ff       	call   800396 <sys_page_unmap>
	return r;
}
  800a30:	89 d8                	mov    %ebx,%eax
  800a32:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  800a35:	8b 75 fc             	mov    -0x4(%ebp),%esi
  800a38:	89 ec                	mov    %ebp,%esp
  800a3a:	5d                   	pop    %ebp
  800a3b:	c3                   	ret    

00800a3c <close>:
	return -E_INVAL;
}

int
close(int fdnum)
{
  800a3c:	55                   	push   %ebp
  800a3d:	89 e5                	mov    %esp,%ebp
  800a3f:	83 ec 28             	sub    $0x28,%esp
	struct Fd *fd;
	int r;

	if ((r = fd_lookup(fdnum, &fd)) < 0)
  800a42:	8d 45 f4             	lea    -0xc(%ebp),%eax
  800a45:	89 44 24 04          	mov    %eax,0x4(%esp)
  800a49:	8b 45 08             	mov    0x8(%ebp),%eax
  800a4c:	89 04 24             	mov    %eax,(%esp)
  800a4f:	e8 c9 fb ff ff       	call   80061d <fd_lookup>
  800a54:	85 c0                	test   %eax,%eax
  800a56:	78 13                	js     800a6b <close+0x2f>
		return r;
	else
		return fd_close(fd, 1);
  800a58:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
  800a5f:	00 
  800a60:	8b 45 f4             	mov    -0xc(%ebp),%eax
  800a63:	89 04 24             	mov    %eax,(%esp)
  800a66:	e8 49 ff ff ff       	call   8009b4 <fd_close>
}
  800a6b:	c9                   	leave  
  800a6c:	c3                   	ret    

00800a6d <stat>:
	return (*dev->dev_stat)(fd, stat);
}

int
stat(const char *path, struct Stat *stat)
{
  800a6d:	55                   	push   %ebp
  800a6e:	89 e5                	mov    %esp,%ebp
  800a70:	83 ec 18             	sub    $0x18,%esp
  800a73:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  800a76:	89 75 fc             	mov    %esi,-0x4(%ebp)
	int fd, r;

	if ((fd = open(path, O_RDONLY)) < 0)
  800a79:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  800a80:	00 
  800a81:	8b 45 08             	mov    0x8(%ebp),%eax
  800a84:	89 04 24             	mov    %eax,(%esp)
  800a87:	e8 80 03 00 00       	call   800e0c <open>
  800a8c:	89 c3                	mov    %eax,%ebx
  800a8e:	85 c0                	test   %eax,%eax
  800a90:	78 1b                	js     800aad <stat+0x40>
		return fd;
	r = fstat(fd, stat);
  800a92:	8b 45 0c             	mov    0xc(%ebp),%eax
  800a95:	89 44 24 04          	mov    %eax,0x4(%esp)
  800a99:	89 1c 24             	mov    %ebx,(%esp)
  800a9c:	e8 5e fc ff ff       	call   8006ff <fstat>
  800aa1:	89 c6                	mov    %eax,%esi
	close(fd);
  800aa3:	89 1c 24             	mov    %ebx,(%esp)
  800aa6:	e8 91 ff ff ff       	call   800a3c <close>
  800aab:	89 f3                	mov    %esi,%ebx
	return r;
}
  800aad:	89 d8                	mov    %ebx,%eax
  800aaf:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  800ab2:	8b 75 fc             	mov    -0x4(%ebp),%esi
  800ab5:	89 ec                	mov    %ebp,%esp
  800ab7:	5d                   	pop    %ebp
  800ab8:	c3                   	ret    

00800ab9 <close_all>:
		return fd_close(fd, 1);
}

void
close_all(void)
{
  800ab9:	55                   	push   %ebp
  800aba:	89 e5                	mov    %esp,%ebp
  800abc:	53                   	push   %ebx
  800abd:	83 ec 14             	sub    $0x14,%esp
  800ac0:	bb 00 00 00 00       	mov    $0x0,%ebx
	int i;
	for (i = 0; i < MAXFD; i++)
		close(i);
  800ac5:	89 1c 24             	mov    %ebx,(%esp)
  800ac8:	e8 6f ff ff ff       	call   800a3c <close>

void
close_all(void)
{
	int i;
	for (i = 0; i < MAXFD; i++)
  800acd:	83 c3 01             	add    $0x1,%ebx
  800ad0:	83 fb 20             	cmp    $0x20,%ebx
  800ad3:	75 f0                	jne    800ac5 <close_all+0xc>
		close(i);
}
  800ad5:	83 c4 14             	add    $0x14,%esp
  800ad8:	5b                   	pop    %ebx
  800ad9:	5d                   	pop    %ebp
  800ada:	c3                   	ret    

00800adb <dup>:
// file and the file offset of the other.
// Closes any previously open file descriptor at 'newfdnum'.
// This is implemented using virtual memory tricks (of course!).
int
dup(int oldfdnum, int newfdnum)
{
  800adb:	55                   	push   %ebp
  800adc:	89 e5                	mov    %esp,%ebp
  800ade:	83 ec 58             	sub    $0x58,%esp
  800ae1:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800ae4:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800ae7:	89 7d fc             	mov    %edi,-0x4(%ebp)
  800aea:	8b 7d 0c             	mov    0xc(%ebp),%edi
	int r;
	char *ova, *nva;
	pte_t pte;
	struct Fd *oldfd, *newfd;

	if ((r = fd_lookup(oldfdnum, &oldfd)) < 0)
  800aed:	8d 45 e4             	lea    -0x1c(%ebp),%eax
  800af0:	89 44 24 04          	mov    %eax,0x4(%esp)
  800af4:	8b 45 08             	mov    0x8(%ebp),%eax
  800af7:	89 04 24             	mov    %eax,(%esp)
  800afa:	e8 1e fb ff ff       	call   80061d <fd_lookup>
  800aff:	89 c3                	mov    %eax,%ebx
  800b01:	85 c0                	test   %eax,%eax
  800b03:	0f 88 e0 00 00 00    	js     800be9 <dup+0x10e>
		return r;
	close(newfdnum);
  800b09:	89 3c 24             	mov    %edi,(%esp)
  800b0c:	e8 2b ff ff ff       	call   800a3c <close>

	newfd = INDEX2FD(newfdnum);
  800b11:	8d b7 00 00 0d 00    	lea    0xd0000(%edi),%esi
  800b17:	c1 e6 0c             	shl    $0xc,%esi
	ova = fd2data(oldfd);
  800b1a:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  800b1d:	89 04 24             	mov    %eax,(%esp)
  800b20:	e8 6b fa ff ff       	call   800590 <fd2data>
  800b25:	89 c3                	mov    %eax,%ebx
	nva = fd2data(newfd);
  800b27:	89 34 24             	mov    %esi,(%esp)
  800b2a:	e8 61 fa ff ff       	call   800590 <fd2data>
  800b2f:	89 45 d4             	mov    %eax,-0x2c(%ebp)
	if ((vpd[PDX(ova)] & PTE_P) && (vpt[VPN(ova)] & PTE_P))
  800b32:	89 da                	mov    %ebx,%edx
  800b34:	89 d8                	mov    %ebx,%eax
  800b36:	c1 e8 16             	shr    $0x16,%eax
  800b39:	8b 04 85 00 d0 7b ef 	mov    -0x10843000(,%eax,4),%eax
  800b40:	a8 01                	test   $0x1,%al
  800b42:	74 43                	je     800b87 <dup+0xac>
  800b44:	c1 ea 0c             	shr    $0xc,%edx
  800b47:	8b 04 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%eax
  800b4e:	a8 01                	test   $0x1,%al
  800b50:	74 35                	je     800b87 <dup+0xac>
		if ((r = sys_page_map(0, ova, 0, nva, (vpt[VPN(ova)]) & PTE_USER)) < 0)
  800b52:	8b 04 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%eax
  800b59:	25 07 0e 00 00       	and    $0xe07,%eax
  800b5e:	89 44 24 10          	mov    %eax,0x10(%esp)
  800b62:	8b 45 d4             	mov    -0x2c(%ebp),%eax
  800b65:	89 44 24 0c          	mov    %eax,0xc(%esp)
  800b69:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  800b70:	00 
  800b71:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  800b75:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  800b7c:	e8 73 f8 ff ff       	call   8003f4 <sys_page_map>
  800b81:	89 c3                	mov    %eax,%ebx
  800b83:	85 c0                	test   %eax,%eax
  800b85:	78 3f                	js     800bc6 <dup+0xeb>
			goto err;
	if ((r = sys_page_map(0, oldfd, 0, newfd, (vpt[VPN(oldfd)]) & PTE_USER)) < 0)
  800b87:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  800b8a:	89 c2                	mov    %eax,%edx
  800b8c:	c1 ea 0c             	shr    $0xc,%edx
  800b8f:	8b 14 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%edx
  800b96:	81 e2 07 0e 00 00    	and    $0xe07,%edx
  800b9c:	89 54 24 10          	mov    %edx,0x10(%esp)
  800ba0:	89 74 24 0c          	mov    %esi,0xc(%esp)
  800ba4:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  800bab:	00 
  800bac:	89 44 24 04          	mov    %eax,0x4(%esp)
  800bb0:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  800bb7:	e8 38 f8 ff ff       	call   8003f4 <sys_page_map>
  800bbc:	89 c3                	mov    %eax,%ebx
  800bbe:	85 c0                	test   %eax,%eax
  800bc0:	78 04                	js     800bc6 <dup+0xeb>
  800bc2:	89 fb                	mov    %edi,%ebx
  800bc4:	eb 23                	jmp    800be9 <dup+0x10e>
		goto err;

	return newfdnum;
err:
	sys_page_unmap(0, newfd);
  800bc6:	89 74 24 04          	mov    %esi,0x4(%esp)
  800bca:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  800bd1:	e8 c0 f7 ff ff       	call   800396 <sys_page_unmap>
	sys_page_unmap(0, nva);
  800bd6:	8b 45 d4             	mov    -0x2c(%ebp),%eax
  800bd9:	89 44 24 04          	mov    %eax,0x4(%esp)
  800bdd:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  800be4:	e8 ad f7 ff ff       	call   800396 <sys_page_unmap>
	return r;
}
  800be9:	89 d8                	mov    %ebx,%eax
  800beb:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800bee:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800bf1:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800bf4:	89 ec                	mov    %ebp,%esp
  800bf6:	5d                   	pop    %ebp
  800bf7:	c3                   	ret    

00800bf8 <fsipc>:
// type: request code, passed as the simple integer IPC value.
// dstva: virtual address at which to receive reply page, 0 if none.
// Returns result from the file server.
static int
fsipc(unsigned type, void *dstva)
{
  800bf8:	55                   	push   %ebp
  800bf9:	89 e5                	mov    %esp,%ebp
  800bfb:	53                   	push   %ebx
  800bfc:	83 ec 14             	sub    $0x14,%esp
  800bff:	89 d3                	mov    %edx,%ebx
	if (debug)
		cprintf("[%08x] fsipc %d %08x\n", env->env_id, type, *(uint32_t *)&fsipcbuf);

	ipc_send(envs[1].env_id, type, &fsipcbuf, PTE_P | PTE_W | PTE_U);
  800c01:	8b 15 c8 00 c0 ee    	mov    0xeec000c8,%edx
  800c07:	c7 44 24 0c 07 00 00 	movl   $0x7,0xc(%esp)
  800c0e:	00 
  800c0f:	c7 44 24 08 00 30 80 	movl   $0x803000,0x8(%esp)
  800c16:	00 
  800c17:	89 44 24 04          	mov    %eax,0x4(%esp)
  800c1b:	89 14 24             	mov    %edx,(%esp)
  800c1e:	e8 4d 18 00 00       	call   802470 <ipc_send>
	return ipc_recv(NULL, dstva, NULL);
  800c23:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  800c2a:	00 
  800c2b:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  800c2f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  800c36:	e8 a7 18 00 00       	call   8024e2 <ipc_recv>
}
  800c3b:	83 c4 14             	add    $0x14,%esp
  800c3e:	5b                   	pop    %ebx
  800c3f:	5d                   	pop    %ebp
  800c40:	c3                   	ret    

00800c41 <devfile_trunc>:
}

// Truncate or extend an open file to 'size' bytes
static int
devfile_trunc(struct Fd *fd, off_t newsize)
{
  800c41:	55                   	push   %ebp
  800c42:	89 e5                	mov    %esp,%ebp
  800c44:	83 ec 08             	sub    $0x8,%esp
	fsipcbuf.set_size.req_fileid = fd->fd_file.id;
  800c47:	8b 45 08             	mov    0x8(%ebp),%eax
  800c4a:	8b 40 0c             	mov    0xc(%eax),%eax
  800c4d:	a3 00 30 80 00       	mov    %eax,0x803000
	fsipcbuf.set_size.req_size = newsize;
  800c52:	8b 45 0c             	mov    0xc(%ebp),%eax
  800c55:	a3 04 30 80 00       	mov    %eax,0x803004
	return fsipc(FSREQ_SET_SIZE, NULL);
  800c5a:	ba 00 00 00 00       	mov    $0x0,%edx
  800c5f:	b8 02 00 00 00       	mov    $0x2,%eax
  800c64:	e8 8f ff ff ff       	call   800bf8 <fsipc>
}
  800c69:	c9                   	leave  
  800c6a:	c3                   	ret    

00800c6b <devfile_flush>:
// open, unmapping it is enough to free up server-side resources.
// Other than that, we just have to make sure our changes are flushed
// to disk.
static int
devfile_flush(struct Fd *fd)
{
  800c6b:	55                   	push   %ebp
  800c6c:	89 e5                	mov    %esp,%ebp
  800c6e:	83 ec 08             	sub    $0x8,%esp
	fsipcbuf.flush.req_fileid = fd->fd_file.id;
  800c71:	8b 45 08             	mov    0x8(%ebp),%eax
  800c74:	8b 40 0c             	mov    0xc(%eax),%eax
  800c77:	a3 00 30 80 00       	mov    %eax,0x803000
	return fsipc(FSREQ_FLUSH, NULL);
  800c7c:	ba 00 00 00 00       	mov    $0x0,%edx
  800c81:	b8 06 00 00 00       	mov    $0x6,%eax
  800c86:	e8 6d ff ff ff       	call   800bf8 <fsipc>
}
  800c8b:	c9                   	leave  
  800c8c:	c3                   	ret    

00800c8d <sync>:
}

// Synchronize disk with buffer cache
int
sync(void)
{
  800c8d:	55                   	push   %ebp
  800c8e:	89 e5                	mov    %esp,%ebp
  800c90:	83 ec 08             	sub    $0x8,%esp
	// Ask the file server to update the disk
	// by writing any dirty blocks in the buffer cache.

	return fsipc(FSREQ_SYNC, NULL);
  800c93:	ba 00 00 00 00       	mov    $0x0,%edx
  800c98:	b8 08 00 00 00       	mov    $0x8,%eax
  800c9d:	e8 56 ff ff ff       	call   800bf8 <fsipc>
}
  800ca2:	c9                   	leave  
  800ca3:	c3                   	ret    

00800ca4 <devfile_stat>:
    return n;
}

static int
devfile_stat(struct Fd *fd, struct Stat *st)
{
  800ca4:	55                   	push   %ebp
  800ca5:	89 e5                	mov    %esp,%ebp
  800ca7:	53                   	push   %ebx
  800ca8:	83 ec 14             	sub    $0x14,%esp
  800cab:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	int r;

	fsipcbuf.stat.req_fileid = fd->fd_file.id;
  800cae:	8b 45 08             	mov    0x8(%ebp),%eax
  800cb1:	8b 40 0c             	mov    0xc(%eax),%eax
  800cb4:	a3 00 30 80 00       	mov    %eax,0x803000
	if ((r = fsipc(FSREQ_STAT, NULL)) < 0)
  800cb9:	ba 00 00 00 00       	mov    $0x0,%edx
  800cbe:	b8 05 00 00 00       	mov    $0x5,%eax
  800cc3:	e8 30 ff ff ff       	call   800bf8 <fsipc>
  800cc8:	85 c0                	test   %eax,%eax
  800cca:	78 2b                	js     800cf7 <devfile_stat+0x53>
		return r;
	strcpy(st->st_name, fsipcbuf.statRet.ret_name);
  800ccc:	c7 44 24 04 00 30 80 	movl   $0x803000,0x4(%esp)
  800cd3:	00 
  800cd4:	89 1c 24             	mov    %ebx,(%esp)
  800cd7:	e8 ce 13 00 00       	call   8020aa <strcpy>
	st->st_size = fsipcbuf.statRet.ret_size;
  800cdc:	a1 80 30 80 00       	mov    0x803080,%eax
  800ce1:	89 83 80 00 00 00    	mov    %eax,0x80(%ebx)
	st->st_isdir = fsipcbuf.statRet.ret_isdir;
  800ce7:	a1 84 30 80 00       	mov    0x803084,%eax
  800cec:	89 83 84 00 00 00    	mov    %eax,0x84(%ebx)
  800cf2:	b8 00 00 00 00       	mov    $0x0,%eax
	return 0;
}
  800cf7:	83 c4 14             	add    $0x14,%esp
  800cfa:	5b                   	pop    %ebx
  800cfb:	5d                   	pop    %ebp
  800cfc:	c3                   	ret    

00800cfd <devfile_write>:
// Returns:
//	 The number of bytes successfully written.
//	 < 0 on error.
static ssize_t
devfile_write(struct Fd *fd, const void *buf, size_t n)
{
  800cfd:	55                   	push   %ebp
  800cfe:	89 e5                	mov    %esp,%ebp
  800d00:	53                   	push   %ebx
  800d01:	83 ec 14             	sub    $0x14,%esp
  800d04:	8b 45 08             	mov    0x8(%ebp),%eax
  800d07:	8b 55 0c             	mov    0xc(%ebp),%edx
  800d0a:	8b 5d 10             	mov    0x10(%ebp),%ebx
	// careful: fsipcbuf.write.req_buf is only so large, but
	// remember that write is always allowed to write *fewer*
	// bytes than requested.
	// LAB 5: Your code here
    int r;
    if (!fd || !buf || (n>(PGSIZE-sizeof(size_t)-sizeof(int))))
  800d0d:	85 c0                	test   %eax,%eax
  800d0f:	74 44                	je     800d55 <devfile_write+0x58>
  800d11:	85 d2                	test   %edx,%edx
  800d13:	74 40                	je     800d55 <devfile_write+0x58>
  800d15:	81 fb f8 0f 00 00    	cmp    $0xff8,%ebx
  800d1b:	77 38                	ja     800d55 <devfile_write+0x58>
        return -E_INVAL;

    fsipcbuf.write.req_fileid   = fd->fd_file.id;
  800d1d:	8b 40 0c             	mov    0xc(%eax),%eax
  800d20:	a3 00 30 80 00       	mov    %eax,0x803000
    fsipcbuf.write.req_n        = n;
  800d25:	89 1d 04 30 80 00    	mov    %ebx,0x803004
    memmove(fsipcbuf.write.req_buf, buf, n);
  800d2b:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  800d2f:	89 54 24 04          	mov    %edx,0x4(%esp)
  800d33:	c7 04 24 08 30 80 00 	movl   $0x803008,(%esp)
  800d3a:	e8 26 15 00 00       	call   802265 <memmove>
    if ((r=fsipc(FSREQ_WRITE, NULL))<0)
  800d3f:	ba 00 00 00 00       	mov    $0x0,%edx
  800d44:	b8 04 00 00 00       	mov    $0x4,%eax
  800d49:	e8 aa fe ff ff       	call   800bf8 <fsipc>
        return r;
    return n;
  800d4e:	85 c0                	test   %eax,%eax
  800d50:	0f 49 c3             	cmovns %ebx,%eax
  800d53:	eb 05                	jmp    800d5a <devfile_write+0x5d>
  800d55:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
}
  800d5a:	83 c4 14             	add    $0x14,%esp
  800d5d:	5b                   	pop    %ebx
  800d5e:	5d                   	pop    %ebp
  800d5f:	c3                   	ret    

00800d60 <devfile_read>:
// Returns:
// 	The number of bytes successfully read.
// 	< 0 on error.
static ssize_t
devfile_read(struct Fd *fd, void *buf, size_t n)
{
  800d60:	55                   	push   %ebp
  800d61:	89 e5                	mov    %esp,%ebp
  800d63:	83 ec 18             	sub    $0x18,%esp
  800d66:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  800d69:	89 75 fc             	mov    %esi,-0x4(%ebp)
  800d6c:	8b 45 08             	mov    0x8(%ebp),%eax
  800d6f:	8b 75 0c             	mov    0xc(%ebp),%esi
	// filling fsipcbuf.read with the request arguments.  The
	// bytes read will be written back to fsipcbuf by the file
	// system server.
	// LAB 5: Your code here
  int r;
  if (!fd || !buf)
  800d72:	85 c0                	test   %eax,%eax
  800d74:	74 04                	je     800d7a <devfile_read+0x1a>
  800d76:	85 f6                	test   %esi,%esi
  800d78:	75 07                	jne    800d81 <devfile_read+0x21>
  800d7a:	bb fd ff ff ff       	mov    $0xfffffffd,%ebx
  800d7f:	eb 39                	jmp    800dba <devfile_read+0x5a>
    return -E_INVAL;

  fsipcbuf.read.req_fileid    = fd->fd_file.id;
  800d81:	8b 40 0c             	mov    0xc(%eax),%eax
  800d84:	a3 00 30 80 00       	mov    %eax,0x803000
  fsipcbuf.read.req_n         = n;
  800d89:	8b 45 10             	mov    0x10(%ebp),%eax
  800d8c:	a3 04 30 80 00       	mov    %eax,0x803004
  if ((r=fsipc(FSREQ_READ, NULL))<0)
  800d91:	ba 00 00 00 00       	mov    $0x0,%edx
  800d96:	b8 03 00 00 00       	mov    $0x3,%eax
  800d9b:	e8 58 fe ff ff       	call   800bf8 <fsipc>
  800da0:	89 c3                	mov    %eax,%ebx
  800da2:	85 c0                	test   %eax,%eax
  800da4:	78 14                	js     800dba <devfile_read+0x5a>
    return r;

  memmove(buf, fsipcbuf.readRet.ret_buf, r);
  800da6:	89 44 24 08          	mov    %eax,0x8(%esp)
  800daa:	c7 44 24 04 00 30 80 	movl   $0x803000,0x4(%esp)
  800db1:	00 
  800db2:	89 34 24             	mov    %esi,(%esp)
  800db5:	e8 ab 14 00 00       	call   802265 <memmove>
  return r;
}
  800dba:	89 d8                	mov    %ebx,%eax
  800dbc:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  800dbf:	8b 75 fc             	mov    -0x4(%ebp),%esi
  800dc2:	89 ec                	mov    %ebp,%esp
  800dc4:	5d                   	pop    %ebp
  800dc5:	c3                   	ret    

00800dc6 <remove>:
}

// Delete a file
int
remove(const char *path)
{
  800dc6:	55                   	push   %ebp
  800dc7:	89 e5                	mov    %esp,%ebp
  800dc9:	53                   	push   %ebx
  800dca:	83 ec 14             	sub    $0x14,%esp
  800dcd:	8b 5d 08             	mov    0x8(%ebp),%ebx
	if (strlen(path) >= MAXPATHLEN)
  800dd0:	89 1c 24             	mov    %ebx,(%esp)
  800dd3:	e8 88 12 00 00       	call   802060 <strlen>
  800dd8:	89 c2                	mov    %eax,%edx
  800dda:	b8 f4 ff ff ff       	mov    $0xfffffff4,%eax
  800ddf:	81 fa ff 03 00 00    	cmp    $0x3ff,%edx
  800de5:	7f 1f                	jg     800e06 <remove+0x40>
		return -E_BAD_PATH;
	strcpy(fsipcbuf.remove.req_path, path);
  800de7:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  800deb:	c7 04 24 00 30 80 00 	movl   $0x803000,(%esp)
  800df2:	e8 b3 12 00 00       	call   8020aa <strcpy>
	return fsipc(FSREQ_REMOVE, NULL);
  800df7:	ba 00 00 00 00       	mov    $0x0,%edx
  800dfc:	b8 07 00 00 00       	mov    $0x7,%eax
  800e01:	e8 f2 fd ff ff       	call   800bf8 <fsipc>
}
  800e06:	83 c4 14             	add    $0x14,%esp
  800e09:	5b                   	pop    %ebx
  800e0a:	5d                   	pop    %ebp
  800e0b:	c3                   	ret    

00800e0c <open>:
// 	The file descriptor index on success
// 	-E_BAD_PATH if the path is too long (>= MAXPATHLEN)
// 	< 0 for other errors.
int
open(const char *path, int mode)
{
  800e0c:	55                   	push   %ebp
  800e0d:	89 e5                	mov    %esp,%ebp
  800e0f:	83 ec 28             	sub    $0x28,%esp
  800e12:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  800e15:	89 75 fc             	mov    %esi,-0x4(%ebp)
  800e18:	8b 75 08             	mov    0x8(%ebp),%esi
	// Return the file descriptor index.
	// If any step after fd_alloc fails, use fd_close to free the
  struct Fd *f    = NULL;
  int r   = 0;

  if (!path)
  800e1b:	bb fd ff ff ff       	mov    $0xfffffffd,%ebx
  800e20:	85 f6                	test   %esi,%esi
  800e22:	74 65                	je     800e89 <open+0x7d>
	// (fd_alloc does not allocate a page, it just returns an
	// unused fd address.  Do you need to allocate a page?)
	//
	// Return the file descriptor index.
	// If any step after fd_alloc fails, use fd_close to free the
  struct Fd *f    = NULL;
  800e24:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  int r   = 0;

  if (!path)
    return -E_INVAL;
  if((r=fd_alloc(&f))<0)
  800e2b:	8d 45 f4             	lea    -0xc(%ebp),%eax
  800e2e:	89 04 24             	mov    %eax,(%esp)
  800e31:	e8 75 f7 ff ff       	call   8005ab <fd_alloc>
  800e36:	89 c3                	mov    %eax,%ebx
  800e38:	85 c0                	test   %eax,%eax
  800e3a:	78 4d                	js     800e89 <open+0x7d>
    return r;

	strcpy(fsipcbuf.open.req_path, path);
  800e3c:	89 74 24 04          	mov    %esi,0x4(%esp)
  800e40:	c7 04 24 00 30 80 00 	movl   $0x803000,(%esp)
  800e47:	e8 5e 12 00 00       	call   8020aa <strcpy>
	fsipcbuf.open.req_omode = mode;
  800e4c:	8b 45 0c             	mov    0xc(%ebp),%eax
  800e4f:	a3 00 34 80 00       	mov    %eax,0x803400

  if ((r=fsipc(FSREQ_OPEN, f))<0) {
  800e54:	8b 55 f4             	mov    -0xc(%ebp),%edx
  800e57:	b8 01 00 00 00       	mov    $0x1,%eax
  800e5c:	e8 97 fd ff ff       	call   800bf8 <fsipc>
  800e61:	89 c3                	mov    %eax,%ebx
  800e63:	85 c0                	test   %eax,%eax
  800e65:	79 15                	jns    800e7c <open+0x70>
    fd_close(f, 0);
  800e67:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  800e6e:	00 
  800e6f:	8b 45 f4             	mov    -0xc(%ebp),%eax
  800e72:	89 04 24             	mov    %eax,(%esp)
  800e75:	e8 3a fb ff ff       	call   8009b4 <fd_close>
    return r;
  800e7a:	eb 0d                	jmp    800e89 <open+0x7d>
  }
  return fd2num(f);
  800e7c:	8b 45 f4             	mov    -0xc(%ebp),%eax
  800e7f:	89 04 24             	mov    %eax,(%esp)
  800e82:	e8 f9 f6 ff ff       	call   800580 <fd2num>
  800e87:	89 c3                	mov    %eax,%ebx
}
  800e89:	89 d8                	mov    %ebx,%eax
  800e8b:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  800e8e:	8b 75 fc             	mov    -0x4(%ebp),%esi
  800e91:	89 ec                	mov    %ebp,%esp
  800e93:	5d                   	pop    %ebp
  800e94:	c3                   	ret    
	...

00800ea0 <devsock_stat>:
	return nsipc_send(fd->fd_sock.sockid, buf, n, 0);
}

static int
devsock_stat(struct Fd *fd, struct Stat *stat)
{
  800ea0:	55                   	push   %ebp
  800ea1:	89 e5                	mov    %esp,%ebp
  800ea3:	83 ec 18             	sub    $0x18,%esp
	strcpy(stat->st_name, "<sock>");
  800ea6:	c7 44 24 04 d8 28 80 	movl   $0x8028d8,0x4(%esp)
  800ead:	00 
  800eae:	8b 45 0c             	mov    0xc(%ebp),%eax
  800eb1:	89 04 24             	mov    %eax,(%esp)
  800eb4:	e8 f1 11 00 00       	call   8020aa <strcpy>
	return 0;
}
  800eb9:	b8 00 00 00 00       	mov    $0x0,%eax
  800ebe:	c9                   	leave  
  800ebf:	c3                   	ret    

00800ec0 <devsock_close>:
	return nsipc_shutdown(r, how);
}

static int
devsock_close(struct Fd *fd)
{
  800ec0:	55                   	push   %ebp
  800ec1:	89 e5                	mov    %esp,%ebp
  800ec3:	83 ec 18             	sub    $0x18,%esp
	return nsipc_close(fd->fd_sock.sockid);
  800ec6:	8b 45 08             	mov    0x8(%ebp),%eax
  800ec9:	8b 40 0c             	mov    0xc(%eax),%eax
  800ecc:	89 04 24             	mov    %eax,(%esp)
  800ecf:	e8 9d 02 00 00       	call   801171 <nsipc_close>
}
  800ed4:	c9                   	leave  
  800ed5:	c3                   	ret    

00800ed6 <devsock_write>:
	return nsipc_recv(fd->fd_sock.sockid, buf, n, 0);
}

static ssize_t
devsock_write(struct Fd *fd, const void *buf, size_t n)
{
  800ed6:	55                   	push   %ebp
  800ed7:	89 e5                	mov    %esp,%ebp
  800ed9:	83 ec 18             	sub    $0x18,%esp
	return nsipc_send(fd->fd_sock.sockid, buf, n, 0);
  800edc:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  800ee3:	00 
  800ee4:	8b 45 10             	mov    0x10(%ebp),%eax
  800ee7:	89 44 24 08          	mov    %eax,0x8(%esp)
  800eeb:	8b 45 0c             	mov    0xc(%ebp),%eax
  800eee:	89 44 24 04          	mov    %eax,0x4(%esp)
  800ef2:	8b 45 08             	mov    0x8(%ebp),%eax
  800ef5:	8b 40 0c             	mov    0xc(%eax),%eax
  800ef8:	89 04 24             	mov    %eax,(%esp)
  800efb:	e8 ad 02 00 00       	call   8011ad <nsipc_send>
}
  800f00:	c9                   	leave  
  800f01:	c3                   	ret    

00800f02 <devsock_read>:
	return nsipc_listen(r, backlog);
}

static ssize_t
devsock_read(struct Fd *fd, void *buf, size_t n)
{
  800f02:	55                   	push   %ebp
  800f03:	89 e5                	mov    %esp,%ebp
  800f05:	83 ec 18             	sub    $0x18,%esp
	return nsipc_recv(fd->fd_sock.sockid, buf, n, 0);
  800f08:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  800f0f:	00 
  800f10:	8b 45 10             	mov    0x10(%ebp),%eax
  800f13:	89 44 24 08          	mov    %eax,0x8(%esp)
  800f17:	8b 45 0c             	mov    0xc(%ebp),%eax
  800f1a:	89 44 24 04          	mov    %eax,0x4(%esp)
  800f1e:	8b 45 08             	mov    0x8(%ebp),%eax
  800f21:	8b 40 0c             	mov    0xc(%eax),%eax
  800f24:	89 04 24             	mov    %eax,(%esp)
  800f27:	e8 f4 02 00 00       	call   801220 <nsipc_recv>
}
  800f2c:	c9                   	leave  
  800f2d:	c3                   	ret    

00800f2e <alloc_sockfd>:
	return sfd->fd_sock.sockid;
}

static int
alloc_sockfd(int sockid)
{
  800f2e:	55                   	push   %ebp
  800f2f:	89 e5                	mov    %esp,%ebp
  800f31:	56                   	push   %esi
  800f32:	53                   	push   %ebx
  800f33:	83 ec 20             	sub    $0x20,%esp
  800f36:	89 c6                	mov    %eax,%esi
	struct Fd *sfd;
	int r;

	if ((r = fd_alloc(&sfd)) < 0
  800f38:	8d 45 f4             	lea    -0xc(%ebp),%eax
  800f3b:	89 04 24             	mov    %eax,(%esp)
  800f3e:	e8 68 f6 ff ff       	call   8005ab <fd_alloc>
  800f43:	89 c3                	mov    %eax,%ebx
  800f45:	85 c0                	test   %eax,%eax
  800f47:	78 21                	js     800f6a <alloc_sockfd+0x3c>
	    || (r = sys_page_alloc(0, sfd, PTE_P|PTE_W|PTE_U)) < 0) {
  800f49:	c7 44 24 08 07 00 00 	movl   $0x7,0x8(%esp)
  800f50:	00 
  800f51:	8b 45 f4             	mov    -0xc(%ebp),%eax
  800f54:	89 44 24 04          	mov    %eax,0x4(%esp)
  800f58:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  800f5f:	e8 ee f4 ff ff       	call   800452 <sys_page_alloc>
  800f64:	89 c3                	mov    %eax,%ebx
alloc_sockfd(int sockid)
{
	struct Fd *sfd;
	int r;

	if ((r = fd_alloc(&sfd)) < 0
  800f66:	85 c0                	test   %eax,%eax
  800f68:	79 0a                	jns    800f74 <alloc_sockfd+0x46>
	    || (r = sys_page_alloc(0, sfd, PTE_P|PTE_W|PTE_U)) < 0) {
		nsipc_close(sockid);
  800f6a:	89 34 24             	mov    %esi,(%esp)
  800f6d:	e8 ff 01 00 00       	call   801171 <nsipc_close>
		return r;
  800f72:	eb 28                	jmp    800f9c <alloc_sockfd+0x6e>
	}

	sfd->fd_dev_id = devsock.dev_id;
  800f74:	8b 15 20 60 80 00    	mov    0x806020,%edx
  800f7a:	8b 45 f4             	mov    -0xc(%ebp),%eax
  800f7d:	89 10                	mov    %edx,(%eax)
	sfd->fd_omode = O_RDWR;
  800f7f:	8b 45 f4             	mov    -0xc(%ebp),%eax
  800f82:	c7 40 08 02 00 00 00 	movl   $0x2,0x8(%eax)
	sfd->fd_sock.sockid = sockid;
  800f89:	8b 45 f4             	mov    -0xc(%ebp),%eax
  800f8c:	89 70 0c             	mov    %esi,0xc(%eax)
	return fd2num(sfd);
  800f8f:	8b 45 f4             	mov    -0xc(%ebp),%eax
  800f92:	89 04 24             	mov    %eax,(%esp)
  800f95:	e8 e6 f5 ff ff       	call   800580 <fd2num>
  800f9a:	89 c3                	mov    %eax,%ebx
}
  800f9c:	89 d8                	mov    %ebx,%eax
  800f9e:	83 c4 20             	add    $0x20,%esp
  800fa1:	5b                   	pop    %ebx
  800fa2:	5e                   	pop    %esi
  800fa3:	5d                   	pop    %ebp
  800fa4:	c3                   	ret    

00800fa5 <socket>:
	return 0;
}

int
socket(int domain, int type, int protocol)
{
  800fa5:	55                   	push   %ebp
  800fa6:	89 e5                	mov    %esp,%ebp
  800fa8:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = nsipc_socket(domain, type, protocol)) < 0)
  800fab:	8b 45 10             	mov    0x10(%ebp),%eax
  800fae:	89 44 24 08          	mov    %eax,0x8(%esp)
  800fb2:	8b 45 0c             	mov    0xc(%ebp),%eax
  800fb5:	89 44 24 04          	mov    %eax,0x4(%esp)
  800fb9:	8b 45 08             	mov    0x8(%ebp),%eax
  800fbc:	89 04 24             	mov    %eax,(%esp)
  800fbf:	e8 61 01 00 00       	call   801125 <nsipc_socket>
  800fc4:	85 c0                	test   %eax,%eax
  800fc6:	78 05                	js     800fcd <socket+0x28>
		return r;
	return alloc_sockfd(r);
  800fc8:	e8 61 ff ff ff       	call   800f2e <alloc_sockfd>
}
  800fcd:	c9                   	leave  
  800fce:	66 90                	xchg   %ax,%ax
  800fd0:	c3                   	ret    

00800fd1 <fd2sockid>:
	.dev_stat =	devsock_stat,
};

static int
fd2sockid(int fd)
{
  800fd1:	55                   	push   %ebp
  800fd2:	89 e5                	mov    %esp,%ebp
  800fd4:	83 ec 28             	sub    $0x28,%esp
	struct Fd *sfd;
	int r;

	if ((r = fd_lookup(fd, &sfd)) < 0)
  800fd7:	8d 55 f4             	lea    -0xc(%ebp),%edx
  800fda:	89 54 24 04          	mov    %edx,0x4(%esp)
  800fde:	89 04 24             	mov    %eax,(%esp)
  800fe1:	e8 37 f6 ff ff       	call   80061d <fd_lookup>
  800fe6:	85 c0                	test   %eax,%eax
  800fe8:	78 15                	js     800fff <fd2sockid+0x2e>
		return r;
	if (sfd->fd_dev_id != devsock.dev_id)
  800fea:	8b 55 f4             	mov    -0xc(%ebp),%edx
  800fed:	8b 0a                	mov    (%edx),%ecx
  800fef:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  800ff4:	3b 0d 20 60 80 00    	cmp    0x806020,%ecx
  800ffa:	75 03                	jne    800fff <fd2sockid+0x2e>
		return -E_NOT_SUPP;
	return sfd->fd_sock.sockid;
  800ffc:	8b 42 0c             	mov    0xc(%edx),%eax
}
  800fff:	c9                   	leave  
  801000:	c3                   	ret    

00801001 <listen>:
	return nsipc_connect(r, name, namelen);
}

int
listen(int s, int backlog)
{
  801001:	55                   	push   %ebp
  801002:	89 e5                	mov    %esp,%ebp
  801004:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  801007:	8b 45 08             	mov    0x8(%ebp),%eax
  80100a:	e8 c2 ff ff ff       	call   800fd1 <fd2sockid>
  80100f:	85 c0                	test   %eax,%eax
  801011:	78 0f                	js     801022 <listen+0x21>
		return r;
	return nsipc_listen(r, backlog);
  801013:	8b 55 0c             	mov    0xc(%ebp),%edx
  801016:	89 54 24 04          	mov    %edx,0x4(%esp)
  80101a:	89 04 24             	mov    %eax,(%esp)
  80101d:	e8 2d 01 00 00       	call   80114f <nsipc_listen>
}
  801022:	c9                   	leave  
  801023:	c3                   	ret    

00801024 <connect>:
	return nsipc_close(fd->fd_sock.sockid);
}

int
connect(int s, const struct sockaddr *name, socklen_t namelen)
{
  801024:	55                   	push   %ebp
  801025:	89 e5                	mov    %esp,%ebp
  801027:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  80102a:	8b 45 08             	mov    0x8(%ebp),%eax
  80102d:	e8 9f ff ff ff       	call   800fd1 <fd2sockid>
  801032:	85 c0                	test   %eax,%eax
  801034:	78 16                	js     80104c <connect+0x28>
		return r;
	return nsipc_connect(r, name, namelen);
  801036:	8b 55 10             	mov    0x10(%ebp),%edx
  801039:	89 54 24 08          	mov    %edx,0x8(%esp)
  80103d:	8b 55 0c             	mov    0xc(%ebp),%edx
  801040:	89 54 24 04          	mov    %edx,0x4(%esp)
  801044:	89 04 24             	mov    %eax,(%esp)
  801047:	e8 54 02 00 00       	call   8012a0 <nsipc_connect>
}
  80104c:	c9                   	leave  
  80104d:	c3                   	ret    

0080104e <shutdown>:
	return nsipc_bind(r, name, namelen);
}

int
shutdown(int s, int how)
{
  80104e:	55                   	push   %ebp
  80104f:	89 e5                	mov    %esp,%ebp
  801051:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  801054:	8b 45 08             	mov    0x8(%ebp),%eax
  801057:	e8 75 ff ff ff       	call   800fd1 <fd2sockid>
  80105c:	85 c0                	test   %eax,%eax
  80105e:	78 0f                	js     80106f <shutdown+0x21>
		return r;
	return nsipc_shutdown(r, how);
  801060:	8b 55 0c             	mov    0xc(%ebp),%edx
  801063:	89 54 24 04          	mov    %edx,0x4(%esp)
  801067:	89 04 24             	mov    %eax,(%esp)
  80106a:	e8 1c 01 00 00       	call   80118b <nsipc_shutdown>
}
  80106f:	c9                   	leave  
  801070:	c3                   	ret    

00801071 <bind>:
	return alloc_sockfd(r);
}

int
bind(int s, struct sockaddr *name, socklen_t namelen)
{
  801071:	55                   	push   %ebp
  801072:	89 e5                	mov    %esp,%ebp
  801074:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  801077:	8b 45 08             	mov    0x8(%ebp),%eax
  80107a:	e8 52 ff ff ff       	call   800fd1 <fd2sockid>
  80107f:	85 c0                	test   %eax,%eax
  801081:	78 16                	js     801099 <bind+0x28>
		return r;
	return nsipc_bind(r, name, namelen);
  801083:	8b 55 10             	mov    0x10(%ebp),%edx
  801086:	89 54 24 08          	mov    %edx,0x8(%esp)
  80108a:	8b 55 0c             	mov    0xc(%ebp),%edx
  80108d:	89 54 24 04          	mov    %edx,0x4(%esp)
  801091:	89 04 24             	mov    %eax,(%esp)
  801094:	e8 46 02 00 00       	call   8012df <nsipc_bind>
}
  801099:	c9                   	leave  
  80109a:	c3                   	ret    

0080109b <accept>:
	return fd2num(sfd);
}

int
accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
  80109b:	55                   	push   %ebp
  80109c:	89 e5                	mov    %esp,%ebp
  80109e:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  8010a1:	8b 45 08             	mov    0x8(%ebp),%eax
  8010a4:	e8 28 ff ff ff       	call   800fd1 <fd2sockid>
  8010a9:	85 c0                	test   %eax,%eax
  8010ab:	78 1f                	js     8010cc <accept+0x31>
		return r;
	if ((r = nsipc_accept(r, addr, addrlen)) < 0)
  8010ad:	8b 55 10             	mov    0x10(%ebp),%edx
  8010b0:	89 54 24 08          	mov    %edx,0x8(%esp)
  8010b4:	8b 55 0c             	mov    0xc(%ebp),%edx
  8010b7:	89 54 24 04          	mov    %edx,0x4(%esp)
  8010bb:	89 04 24             	mov    %eax,(%esp)
  8010be:	e8 5b 02 00 00       	call   80131e <nsipc_accept>
  8010c3:	85 c0                	test   %eax,%eax
  8010c5:	78 05                	js     8010cc <accept+0x31>
		return r;
	return alloc_sockfd(r);
  8010c7:	e8 62 fe ff ff       	call   800f2e <alloc_sockfd>
}
  8010cc:	c9                   	leave  
  8010cd:	8d 76 00             	lea    0x0(%esi),%esi
  8010d0:	c3                   	ret    
	...

008010e0 <nsipc>:
// may be written back to nsipcbuf.
// type: request code, passed as the simple integer IPC value.
// Returns 0 if successful, < 0 on failure.
static int
nsipc(unsigned type)
{
  8010e0:	55                   	push   %ebp
  8010e1:	89 e5                	mov    %esp,%ebp
  8010e3:	83 ec 28             	sub    $0x28,%esp
    int r=0;
    envid_t from;
	if (debug)
		cprintf("[%08x] nsipc %d\n", env->env_id, type);

	ipc_send(envs[2].env_id, type, &nsipcbuf, PTE_P|PTE_W|PTE_U);
  8010e6:	8b 15 44 01 c0 ee    	mov    0xeec00144,%edx
  8010ec:	c7 44 24 0c 07 00 00 	movl   $0x7,0xc(%esp)
  8010f3:	00 
  8010f4:	c7 44 24 08 00 50 80 	movl   $0x805000,0x8(%esp)
  8010fb:	00 
  8010fc:	89 44 24 04          	mov    %eax,0x4(%esp)
  801100:	89 14 24             	mov    %edx,(%esp)
  801103:	e8 68 13 00 00       	call   802470 <ipc_send>
	r=ipc_recv(&from, NULL, NULL);
  801108:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  80110f:	00 
  801110:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  801117:	00 
  801118:	8d 45 f4             	lea    -0xc(%ebp),%eax
  80111b:	89 04 24             	mov    %eax,(%esp)
  80111e:	e8 bf 13 00 00       	call   8024e2 <ipc_recv>
    return r;
}
  801123:	c9                   	leave  
  801124:	c3                   	ret    

00801125 <nsipc_socket>:
	return nsipc(NSREQ_SEND);
}

int
nsipc_socket(int domain, int type, int protocol)
{
  801125:	55                   	push   %ebp
  801126:	89 e5                	mov    %esp,%ebp
  801128:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.socket.req_domain = domain;
  80112b:	8b 45 08             	mov    0x8(%ebp),%eax
  80112e:	a3 00 50 80 00       	mov    %eax,0x805000
	nsipcbuf.socket.req_type = type;
  801133:	8b 45 0c             	mov    0xc(%ebp),%eax
  801136:	a3 04 50 80 00       	mov    %eax,0x805004
	nsipcbuf.socket.req_protocol = protocol;
  80113b:	8b 45 10             	mov    0x10(%ebp),%eax
  80113e:	a3 08 50 80 00       	mov    %eax,0x805008
	return nsipc(NSREQ_SOCKET);
  801143:	b8 09 00 00 00       	mov    $0x9,%eax
  801148:	e8 93 ff ff ff       	call   8010e0 <nsipc>
}
  80114d:	c9                   	leave  
  80114e:	c3                   	ret    

0080114f <nsipc_listen>:
	return nsipc(NSREQ_CONNECT);
}

int
nsipc_listen(int s, int backlog)
{
  80114f:	55                   	push   %ebp
  801150:	89 e5                	mov    %esp,%ebp
  801152:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.listen.req_s = s;
  801155:	8b 45 08             	mov    0x8(%ebp),%eax
  801158:	a3 00 50 80 00       	mov    %eax,0x805000
	nsipcbuf.listen.req_backlog = backlog;
  80115d:	8b 45 0c             	mov    0xc(%ebp),%eax
  801160:	a3 04 50 80 00       	mov    %eax,0x805004
	return nsipc(NSREQ_LISTEN);
  801165:	b8 06 00 00 00       	mov    $0x6,%eax
  80116a:	e8 71 ff ff ff       	call   8010e0 <nsipc>
}
  80116f:	c9                   	leave  
  801170:	c3                   	ret    

00801171 <nsipc_close>:
	return nsipc(NSREQ_SHUTDOWN);
}

int
nsipc_close(int s)
{
  801171:	55                   	push   %ebp
  801172:	89 e5                	mov    %esp,%ebp
  801174:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.close.req_s = s;
  801177:	8b 45 08             	mov    0x8(%ebp),%eax
  80117a:	a3 00 50 80 00       	mov    %eax,0x805000
	return nsipc(NSREQ_CLOSE);
  80117f:	b8 04 00 00 00       	mov    $0x4,%eax
  801184:	e8 57 ff ff ff       	call   8010e0 <nsipc>
}
  801189:	c9                   	leave  
  80118a:	c3                   	ret    

0080118b <nsipc_shutdown>:
	return nsipc(NSREQ_BIND);
}

int
nsipc_shutdown(int s, int how)
{
  80118b:	55                   	push   %ebp
  80118c:	89 e5                	mov    %esp,%ebp
  80118e:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.shutdown.req_s = s;
  801191:	8b 45 08             	mov    0x8(%ebp),%eax
  801194:	a3 00 50 80 00       	mov    %eax,0x805000
	nsipcbuf.shutdown.req_how = how;
  801199:	8b 45 0c             	mov    0xc(%ebp),%eax
  80119c:	a3 04 50 80 00       	mov    %eax,0x805004
	return nsipc(NSREQ_SHUTDOWN);
  8011a1:	b8 03 00 00 00       	mov    $0x3,%eax
  8011a6:	e8 35 ff ff ff       	call   8010e0 <nsipc>
}
  8011ab:	c9                   	leave  
  8011ac:	c3                   	ret    

008011ad <nsipc_send>:
	return r;
}

int
nsipc_send(int s, const void *buf, int size, unsigned int flags)
{
  8011ad:	55                   	push   %ebp
  8011ae:	89 e5                	mov    %esp,%ebp
  8011b0:	53                   	push   %ebx
  8011b1:	83 ec 14             	sub    $0x14,%esp
  8011b4:	8b 5d 10             	mov    0x10(%ebp),%ebx
	nsipcbuf.send.req_s = s;
  8011b7:	8b 45 08             	mov    0x8(%ebp),%eax
  8011ba:	a3 00 50 80 00       	mov    %eax,0x805000
	assert(size < 1600);
  8011bf:	81 fb 3f 06 00 00    	cmp    $0x63f,%ebx
  8011c5:	7e 24                	jle    8011eb <nsipc_send+0x3e>
  8011c7:	c7 44 24 0c e4 28 80 	movl   $0x8028e4,0xc(%esp)
  8011ce:	00 
  8011cf:	c7 44 24 08 f0 28 80 	movl   $0x8028f0,0x8(%esp)
  8011d6:	00 
  8011d7:	c7 44 24 04 69 00 00 	movl   $0x69,0x4(%esp)
  8011de:	00 
  8011df:	c7 04 24 05 29 80 00 	movl   $0x802905,(%esp)
  8011e6:	e8 29 07 00 00       	call   801914 <_panic>
	memmove(&nsipcbuf.send.req_buf, buf, size);
  8011eb:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8011ef:	8b 45 0c             	mov    0xc(%ebp),%eax
  8011f2:	89 44 24 04          	mov    %eax,0x4(%esp)
  8011f6:	c7 04 24 0c 50 80 00 	movl   $0x80500c,(%esp)
  8011fd:	e8 63 10 00 00       	call   802265 <memmove>
	nsipcbuf.send.req_size = size;
  801202:	89 1d 04 50 80 00    	mov    %ebx,0x805004
	nsipcbuf.send.req_flags = flags;
  801208:	8b 45 14             	mov    0x14(%ebp),%eax
  80120b:	a3 08 50 80 00       	mov    %eax,0x805008
	return nsipc(NSREQ_SEND);
  801210:	b8 08 00 00 00       	mov    $0x8,%eax
  801215:	e8 c6 fe ff ff       	call   8010e0 <nsipc>
}
  80121a:	83 c4 14             	add    $0x14,%esp
  80121d:	5b                   	pop    %ebx
  80121e:	5d                   	pop    %ebp
  80121f:	c3                   	ret    

00801220 <nsipc_recv>:
	return nsipc(NSREQ_LISTEN);
}

int
nsipc_recv(int s, void *mem, int len, unsigned int flags)
{
  801220:	55                   	push   %ebp
  801221:	89 e5                	mov    %esp,%ebp
  801223:	56                   	push   %esi
  801224:	53                   	push   %ebx
  801225:	83 ec 10             	sub    $0x10,%esp
  801228:	8b 75 10             	mov    0x10(%ebp),%esi
	int r;

	nsipcbuf.recv.req_s = s;
  80122b:	8b 45 08             	mov    0x8(%ebp),%eax
  80122e:	a3 00 50 80 00       	mov    %eax,0x805000
	nsipcbuf.recv.req_len = len;
  801233:	89 35 04 50 80 00    	mov    %esi,0x805004
	nsipcbuf.recv.req_flags = flags;
  801239:	8b 45 14             	mov    0x14(%ebp),%eax
  80123c:	a3 08 50 80 00       	mov    %eax,0x805008

	if ((r = nsipc(NSREQ_RECV)) >= 0) {
  801241:	b8 07 00 00 00       	mov    $0x7,%eax
  801246:	e8 95 fe ff ff       	call   8010e0 <nsipc>
  80124b:	89 c3                	mov    %eax,%ebx
  80124d:	85 c0                	test   %eax,%eax
  80124f:	78 46                	js     801297 <nsipc_recv+0x77>
		assert(r < 1600 && r <= len);
  801251:	3d 3f 06 00 00       	cmp    $0x63f,%eax
  801256:	7f 04                	jg     80125c <nsipc_recv+0x3c>
  801258:	39 c6                	cmp    %eax,%esi
  80125a:	7d 24                	jge    801280 <nsipc_recv+0x60>
  80125c:	c7 44 24 0c 11 29 80 	movl   $0x802911,0xc(%esp)
  801263:	00 
  801264:	c7 44 24 08 f0 28 80 	movl   $0x8028f0,0x8(%esp)
  80126b:	00 
  80126c:	c7 44 24 04 5e 00 00 	movl   $0x5e,0x4(%esp)
  801273:	00 
  801274:	c7 04 24 05 29 80 00 	movl   $0x802905,(%esp)
  80127b:	e8 94 06 00 00       	call   801914 <_panic>
		memmove(mem, nsipcbuf.recvRet.ret_buf, r);
  801280:	89 44 24 08          	mov    %eax,0x8(%esp)
  801284:	c7 44 24 04 00 50 80 	movl   $0x805000,0x4(%esp)
  80128b:	00 
  80128c:	8b 45 0c             	mov    0xc(%ebp),%eax
  80128f:	89 04 24             	mov    %eax,(%esp)
  801292:	e8 ce 0f 00 00       	call   802265 <memmove>
	}

	return r;
}
  801297:	89 d8                	mov    %ebx,%eax
  801299:	83 c4 10             	add    $0x10,%esp
  80129c:	5b                   	pop    %ebx
  80129d:	5e                   	pop    %esi
  80129e:	5d                   	pop    %ebp
  80129f:	c3                   	ret    

008012a0 <nsipc_connect>:
	return nsipc(NSREQ_CLOSE);
}

int
nsipc_connect(int s, const struct sockaddr *name, socklen_t namelen)
{
  8012a0:	55                   	push   %ebp
  8012a1:	89 e5                	mov    %esp,%ebp
  8012a3:	53                   	push   %ebx
  8012a4:	83 ec 14             	sub    $0x14,%esp
  8012a7:	8b 5d 10             	mov    0x10(%ebp),%ebx
	nsipcbuf.connect.req_s = s;
  8012aa:	8b 45 08             	mov    0x8(%ebp),%eax
  8012ad:	a3 00 50 80 00       	mov    %eax,0x805000
	memmove(&nsipcbuf.connect.req_name, name, namelen);
  8012b2:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8012b6:	8b 45 0c             	mov    0xc(%ebp),%eax
  8012b9:	89 44 24 04          	mov    %eax,0x4(%esp)
  8012bd:	c7 04 24 04 50 80 00 	movl   $0x805004,(%esp)
  8012c4:	e8 9c 0f 00 00       	call   802265 <memmove>
	nsipcbuf.connect.req_namelen = namelen;
  8012c9:	89 1d 14 50 80 00    	mov    %ebx,0x805014
	return nsipc(NSREQ_CONNECT);
  8012cf:	b8 05 00 00 00       	mov    $0x5,%eax
  8012d4:	e8 07 fe ff ff       	call   8010e0 <nsipc>
}
  8012d9:	83 c4 14             	add    $0x14,%esp
  8012dc:	5b                   	pop    %ebx
  8012dd:	5d                   	pop    %ebp
  8012de:	c3                   	ret    

008012df <nsipc_bind>:
	return r;
}

int
nsipc_bind(int s, struct sockaddr *name, socklen_t namelen)
{
  8012df:	55                   	push   %ebp
  8012e0:	89 e5                	mov    %esp,%ebp
  8012e2:	53                   	push   %ebx
  8012e3:	83 ec 14             	sub    $0x14,%esp
  8012e6:	8b 5d 10             	mov    0x10(%ebp),%ebx
	nsipcbuf.bind.req_s = s;
  8012e9:	8b 45 08             	mov    0x8(%ebp),%eax
  8012ec:	a3 00 50 80 00       	mov    %eax,0x805000
	memmove(&nsipcbuf.bind.req_name, name, namelen);
  8012f1:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8012f5:	8b 45 0c             	mov    0xc(%ebp),%eax
  8012f8:	89 44 24 04          	mov    %eax,0x4(%esp)
  8012fc:	c7 04 24 04 50 80 00 	movl   $0x805004,(%esp)
  801303:	e8 5d 0f 00 00       	call   802265 <memmove>
	nsipcbuf.bind.req_namelen = namelen;
  801308:	89 1d 14 50 80 00    	mov    %ebx,0x805014
	return nsipc(NSREQ_BIND);
  80130e:	b8 02 00 00 00       	mov    $0x2,%eax
  801313:	e8 c8 fd ff ff       	call   8010e0 <nsipc>
}
  801318:	83 c4 14             	add    $0x14,%esp
  80131b:	5b                   	pop    %ebx
  80131c:	5d                   	pop    %ebp
  80131d:	c3                   	ret    

0080131e <nsipc_accept>:
    return r;
}

int
nsipc_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
  80131e:	55                   	push   %ebp
  80131f:	89 e5                	mov    %esp,%ebp
  801321:	83 ec 18             	sub    $0x18,%esp
  801324:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  801327:	89 75 fc             	mov    %esi,-0x4(%ebp)
	int r;
	
	nsipcbuf.accept.req_s = s;
  80132a:	8b 45 08             	mov    0x8(%ebp),%eax
  80132d:	a3 00 50 80 00       	mov    %eax,0x805000
	if ((r = nsipc(NSREQ_ACCEPT)) >= 0) {
  801332:	b8 01 00 00 00       	mov    $0x1,%eax
  801337:	e8 a4 fd ff ff       	call   8010e0 <nsipc>
  80133c:	89 c3                	mov    %eax,%ebx
  80133e:	85 c0                	test   %eax,%eax
  801340:	78 25                	js     801367 <nsipc_accept+0x49>
		struct Nsret_accept *ret = &nsipcbuf.acceptRet;
		memmove(addr, &ret->ret_addr, ret->ret_addrlen);
  801342:	be 10 50 80 00       	mov    $0x805010,%esi
  801347:	8b 06                	mov    (%esi),%eax
  801349:	89 44 24 08          	mov    %eax,0x8(%esp)
  80134d:	c7 44 24 04 00 50 80 	movl   $0x805000,0x4(%esp)
  801354:	00 
  801355:	8b 45 0c             	mov    0xc(%ebp),%eax
  801358:	89 04 24             	mov    %eax,(%esp)
  80135b:	e8 05 0f 00 00       	call   802265 <memmove>
		*addrlen = ret->ret_addrlen;
  801360:	8b 16                	mov    (%esi),%edx
  801362:	8b 45 10             	mov    0x10(%ebp),%eax
  801365:	89 10                	mov    %edx,(%eax)
	}
	return r;
}
  801367:	89 d8                	mov    %ebx,%eax
  801369:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  80136c:	8b 75 fc             	mov    -0x4(%ebp),%esi
  80136f:	89 ec                	mov    %ebp,%esp
  801371:	5d                   	pop    %ebp
  801372:	c3                   	ret    
	...

00801380 <devpipe_stat>:
	return i;
}

static int
devpipe_stat(struct Fd *fd, struct Stat *stat)
{
  801380:	55                   	push   %ebp
  801381:	89 e5                	mov    %esp,%ebp
  801383:	83 ec 18             	sub    $0x18,%esp
  801386:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  801389:	89 75 fc             	mov    %esi,-0x4(%ebp)
  80138c:	8b 75 0c             	mov    0xc(%ebp),%esi
	struct Pipe *p = (struct Pipe*) fd2data(fd);
  80138f:	8b 45 08             	mov    0x8(%ebp),%eax
  801392:	89 04 24             	mov    %eax,(%esp)
  801395:	e8 f6 f1 ff ff       	call   800590 <fd2data>
  80139a:	89 c3                	mov    %eax,%ebx
	strcpy(stat->st_name, "<pipe>");
  80139c:	c7 44 24 04 26 29 80 	movl   $0x802926,0x4(%esp)
  8013a3:	00 
  8013a4:	89 34 24             	mov    %esi,(%esp)
  8013a7:	e8 fe 0c 00 00       	call   8020aa <strcpy>
	stat->st_size = p->p_wpos - p->p_rpos;
  8013ac:	8b 43 04             	mov    0x4(%ebx),%eax
  8013af:	2b 03                	sub    (%ebx),%eax
  8013b1:	89 86 80 00 00 00    	mov    %eax,0x80(%esi)
	stat->st_isdir = 0;
  8013b7:	c7 86 84 00 00 00 00 	movl   $0x0,0x84(%esi)
  8013be:	00 00 00 
	stat->st_dev = &devpipe;
  8013c1:	c7 86 88 00 00 00 3c 	movl   $0x80603c,0x88(%esi)
  8013c8:	60 80 00 
	return 0;
}
  8013cb:	b8 00 00 00 00       	mov    $0x0,%eax
  8013d0:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  8013d3:	8b 75 fc             	mov    -0x4(%ebp),%esi
  8013d6:	89 ec                	mov    %ebp,%esp
  8013d8:	5d                   	pop    %ebp
  8013d9:	c3                   	ret    

008013da <devpipe_close>:

static int
devpipe_close(struct Fd *fd)
{
  8013da:	55                   	push   %ebp
  8013db:	89 e5                	mov    %esp,%ebp
  8013dd:	53                   	push   %ebx
  8013de:	83 ec 14             	sub    $0x14,%esp
  8013e1:	8b 5d 08             	mov    0x8(%ebp),%ebx
	(void) sys_page_unmap(0, fd);
  8013e4:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  8013e8:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8013ef:	e8 a2 ef ff ff       	call   800396 <sys_page_unmap>
	return sys_page_unmap(0, fd2data(fd));
  8013f4:	89 1c 24             	mov    %ebx,(%esp)
  8013f7:	e8 94 f1 ff ff       	call   800590 <fd2data>
  8013fc:	89 44 24 04          	mov    %eax,0x4(%esp)
  801400:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801407:	e8 8a ef ff ff       	call   800396 <sys_page_unmap>
}
  80140c:	83 c4 14             	add    $0x14,%esp
  80140f:	5b                   	pop    %ebx
  801410:	5d                   	pop    %ebp
  801411:	c3                   	ret    

00801412 <_pipeisclosed>:
	return r;
}

static int
_pipeisclosed(struct Fd *fd, struct Pipe *p)
{
  801412:	55                   	push   %ebp
  801413:	89 e5                	mov    %esp,%ebp
  801415:	57                   	push   %edi
  801416:	56                   	push   %esi
  801417:	53                   	push   %ebx
  801418:	83 ec 2c             	sub    $0x2c,%esp
  80141b:	89 c7                	mov    %eax,%edi
  80141d:	89 55 e4             	mov    %edx,-0x1c(%ebp)
	int n, nn, ret;

	while (1) {
		n = env->env_runs;
  801420:	a1 74 60 80 00       	mov    0x806074,%eax
  801425:	8b 58 58             	mov    0x58(%eax),%ebx
		ret = pageref(fd) == pageref(p);
  801428:	89 3c 24             	mov    %edi,(%esp)
  80142b:	e8 04 11 00 00       	call   802534 <pageref>
  801430:	89 c6                	mov    %eax,%esi
  801432:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801435:	89 04 24             	mov    %eax,(%esp)
  801438:	e8 f7 10 00 00       	call   802534 <pageref>
  80143d:	39 c6                	cmp    %eax,%esi
  80143f:	0f 94 c0             	sete   %al
  801442:	0f b6 c0             	movzbl %al,%eax
		nn = env->env_runs;
  801445:	8b 15 74 60 80 00    	mov    0x806074,%edx
  80144b:	8b 4a 58             	mov    0x58(%edx),%ecx
		if (n == nn)
  80144e:	39 cb                	cmp    %ecx,%ebx
  801450:	75 08                	jne    80145a <_pipeisclosed+0x48>
			return ret;
		if (n != nn && ret == 1)
			cprintf("pipe race avoided\n", n, env->env_runs, ret);
	}
}
  801452:	83 c4 2c             	add    $0x2c,%esp
  801455:	5b                   	pop    %ebx
  801456:	5e                   	pop    %esi
  801457:	5f                   	pop    %edi
  801458:	5d                   	pop    %ebp
  801459:	c3                   	ret    
		n = env->env_runs;
		ret = pageref(fd) == pageref(p);
		nn = env->env_runs;
		if (n == nn)
			return ret;
		if (n != nn && ret == 1)
  80145a:	83 f8 01             	cmp    $0x1,%eax
  80145d:	75 c1                	jne    801420 <_pipeisclosed+0xe>
			cprintf("pipe race avoided\n", n, env->env_runs, ret);
  80145f:	8b 52 58             	mov    0x58(%edx),%edx
  801462:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801466:	89 54 24 08          	mov    %edx,0x8(%esp)
  80146a:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  80146e:	c7 04 24 2d 29 80 00 	movl   $0x80292d,(%esp)
  801475:	e8 5f 05 00 00       	call   8019d9 <cprintf>
  80147a:	eb a4                	jmp    801420 <_pipeisclosed+0xe>

0080147c <devpipe_write>:
	return i;
}

static ssize_t
devpipe_write(struct Fd *fd, const void *vbuf, size_t n)
{
  80147c:	55                   	push   %ebp
  80147d:	89 e5                	mov    %esp,%ebp
  80147f:	57                   	push   %edi
  801480:	56                   	push   %esi
  801481:	53                   	push   %ebx
  801482:	83 ec 1c             	sub    $0x1c,%esp
  801485:	8b 75 08             	mov    0x8(%ebp),%esi
	const uint8_t *buf;
	size_t i;
	struct Pipe *p;

	p = (struct Pipe*) fd2data(fd);
  801488:	89 34 24             	mov    %esi,(%esp)
  80148b:	e8 00 f1 ff ff       	call   800590 <fd2data>
  801490:	89 c3                	mov    %eax,%ebx
	if (debug)
		cprintf("[%08x] devpipe_write %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  801492:	bf 00 00 00 00       	mov    $0x0,%edi
  801497:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  80149b:	75 54                	jne    8014f1 <devpipe_write+0x75>
  80149d:	eb 60                	jmp    8014ff <devpipe_write+0x83>
		while (p->p_wpos >= p->p_rpos + sizeof(p->p_buf)) {
			// pipe is full
			// if all the readers are gone
			// (it's only writers like us now),
			// note eof
			if (_pipeisclosed(fd, p))
  80149f:	89 da                	mov    %ebx,%edx
  8014a1:	89 f0                	mov    %esi,%eax
  8014a3:	e8 6a ff ff ff       	call   801412 <_pipeisclosed>
  8014a8:	85 c0                	test   %eax,%eax
  8014aa:	74 07                	je     8014b3 <devpipe_write+0x37>
  8014ac:	b8 00 00 00 00       	mov    $0x0,%eax
  8014b1:	eb 53                	jmp    801506 <devpipe_write+0x8a>
				return 0;
			// yield and see what happens
			if (debug)
				cprintf("devpipe_write yield\n");
			sys_yield();
  8014b3:	90                   	nop
  8014b4:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  8014b8:	e8 f4 ef ff ff       	call   8004b1 <sys_yield>
		cprintf("[%08x] devpipe_write %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
		while (p->p_wpos >= p->p_rpos + sizeof(p->p_buf)) {
  8014bd:	8b 43 04             	mov    0x4(%ebx),%eax
  8014c0:	8b 13                	mov    (%ebx),%edx
  8014c2:	83 c2 20             	add    $0x20,%edx
  8014c5:	39 d0                	cmp    %edx,%eax
  8014c7:	73 d6                	jae    80149f <devpipe_write+0x23>
				cprintf("devpipe_write yield\n");
			sys_yield();
		}
		// there's room for a byte.  store it.
		// wait to increment wpos until the byte is stored!
		p->p_buf[p->p_wpos % PIPEBUFSIZ] = buf[i];
  8014c9:	89 c2                	mov    %eax,%edx
  8014cb:	c1 fa 1f             	sar    $0x1f,%edx
  8014ce:	c1 ea 1b             	shr    $0x1b,%edx
  8014d1:	01 d0                	add    %edx,%eax
  8014d3:	83 e0 1f             	and    $0x1f,%eax
  8014d6:	29 d0                	sub    %edx,%eax
  8014d8:	89 c2                	mov    %eax,%edx
  8014da:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  8014dd:	0f b6 04 39          	movzbl (%ecx,%edi,1),%eax
  8014e1:	88 44 13 08          	mov    %al,0x8(%ebx,%edx,1)
		p->p_wpos++;
  8014e5:	83 43 04 01          	addl   $0x1,0x4(%ebx)
	if (debug)
		cprintf("[%08x] devpipe_write %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  8014e9:	83 c7 01             	add    $0x1,%edi
  8014ec:	39 7d 10             	cmp    %edi,0x10(%ebp)
  8014ef:	76 13                	jbe    801504 <devpipe_write+0x88>
		while (p->p_wpos >= p->p_rpos + sizeof(p->p_buf)) {
  8014f1:	8b 43 04             	mov    0x4(%ebx),%eax
  8014f4:	8b 13                	mov    (%ebx),%edx
  8014f6:	83 c2 20             	add    $0x20,%edx
  8014f9:	39 d0                	cmp    %edx,%eax
  8014fb:	73 a2                	jae    80149f <devpipe_write+0x23>
  8014fd:	eb ca                	jmp    8014c9 <devpipe_write+0x4d>
  8014ff:	bf 00 00 00 00       	mov    $0x0,%edi
		// wait to increment wpos until the byte is stored!
		p->p_buf[p->p_wpos % PIPEBUFSIZ] = buf[i];
		p->p_wpos++;
	}
	
	return i;
  801504:	89 f8                	mov    %edi,%eax
}
  801506:	83 c4 1c             	add    $0x1c,%esp
  801509:	5b                   	pop    %ebx
  80150a:	5e                   	pop    %esi
  80150b:	5f                   	pop    %edi
  80150c:	5d                   	pop    %ebp
  80150d:	c3                   	ret    

0080150e <devpipe_read>:
	return _pipeisclosed(fd, p);
}

static ssize_t
devpipe_read(struct Fd *fd, void *vbuf, size_t n)
{
  80150e:	55                   	push   %ebp
  80150f:	89 e5                	mov    %esp,%ebp
  801511:	83 ec 28             	sub    $0x28,%esp
  801514:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  801517:	89 75 f8             	mov    %esi,-0x8(%ebp)
  80151a:	89 7d fc             	mov    %edi,-0x4(%ebp)
  80151d:	8b 7d 08             	mov    0x8(%ebp),%edi
	uint8_t *buf;
	size_t i;
	struct Pipe *p;

	p = (struct Pipe*)fd2data(fd);
  801520:	89 3c 24             	mov    %edi,(%esp)
  801523:	e8 68 f0 ff ff       	call   800590 <fd2data>
  801528:	89 c3                	mov    %eax,%ebx
	if (debug)
		cprintf("[%08x] devpipe_read %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  80152a:	be 00 00 00 00       	mov    $0x0,%esi
  80152f:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  801533:	75 4c                	jne    801581 <devpipe_read+0x73>
  801535:	eb 5b                	jmp    801592 <devpipe_read+0x84>
		while (p->p_rpos == p->p_wpos) {
			// pipe is empty
			// if we got any data, return it
			if (i > 0)
				return i;
  801537:	89 f0                	mov    %esi,%eax
  801539:	eb 5e                	jmp    801599 <devpipe_read+0x8b>
			// if all the writers are gone, note eof
			if (_pipeisclosed(fd, p))
  80153b:	89 da                	mov    %ebx,%edx
  80153d:	89 f8                	mov    %edi,%eax
  80153f:	90                   	nop
  801540:	e8 cd fe ff ff       	call   801412 <_pipeisclosed>
  801545:	85 c0                	test   %eax,%eax
  801547:	74 07                	je     801550 <devpipe_read+0x42>
  801549:	b8 00 00 00 00       	mov    $0x0,%eax
  80154e:	eb 49                	jmp    801599 <devpipe_read+0x8b>
				return 0;
			// yield and see what happens
			if (debug)
				cprintf("devpipe_read yield\n");
			sys_yield();
  801550:	e8 5c ef ff ff       	call   8004b1 <sys_yield>
		cprintf("[%08x] devpipe_read %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
		while (p->p_rpos == p->p_wpos) {
  801555:	8b 03                	mov    (%ebx),%eax
  801557:	3b 43 04             	cmp    0x4(%ebx),%eax
  80155a:	74 df                	je     80153b <devpipe_read+0x2d>
				cprintf("devpipe_read yield\n");
			sys_yield();
		}
		// there's a byte.  take it.
		// wait to increment rpos until the byte is taken!
		buf[i] = p->p_buf[p->p_rpos % PIPEBUFSIZ];
  80155c:	89 c2                	mov    %eax,%edx
  80155e:	c1 fa 1f             	sar    $0x1f,%edx
  801561:	c1 ea 1b             	shr    $0x1b,%edx
  801564:	01 d0                	add    %edx,%eax
  801566:	83 e0 1f             	and    $0x1f,%eax
  801569:	29 d0                	sub    %edx,%eax
  80156b:	0f b6 44 03 08       	movzbl 0x8(%ebx,%eax,1),%eax
  801570:	8b 55 0c             	mov    0xc(%ebp),%edx
  801573:	88 04 32             	mov    %al,(%edx,%esi,1)
		p->p_rpos++;
  801576:	83 03 01             	addl   $0x1,(%ebx)
	if (debug)
		cprintf("[%08x] devpipe_read %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  801579:	83 c6 01             	add    $0x1,%esi
  80157c:	39 75 10             	cmp    %esi,0x10(%ebp)
  80157f:	76 16                	jbe    801597 <devpipe_read+0x89>
		while (p->p_rpos == p->p_wpos) {
  801581:	8b 03                	mov    (%ebx),%eax
  801583:	3b 43 04             	cmp    0x4(%ebx),%eax
  801586:	75 d4                	jne    80155c <devpipe_read+0x4e>
			// pipe is empty
			// if we got any data, return it
			if (i > 0)
  801588:	85 f6                	test   %esi,%esi
  80158a:	75 ab                	jne    801537 <devpipe_read+0x29>
  80158c:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  801590:	eb a9                	jmp    80153b <devpipe_read+0x2d>
  801592:	be 00 00 00 00       	mov    $0x0,%esi
		// there's a byte.  take it.
		// wait to increment rpos until the byte is taken!
		buf[i] = p->p_buf[p->p_rpos % PIPEBUFSIZ];
		p->p_rpos++;
	}
	return i;
  801597:	89 f0                	mov    %esi,%eax
}
  801599:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  80159c:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80159f:	8b 7d fc             	mov    -0x4(%ebp),%edi
  8015a2:	89 ec                	mov    %ebp,%esp
  8015a4:	5d                   	pop    %ebp
  8015a5:	c3                   	ret    

008015a6 <pipeisclosed>:
	}
}

int
pipeisclosed(int fdnum)
{
  8015a6:	55                   	push   %ebp
  8015a7:	89 e5                	mov    %esp,%ebp
  8015a9:	83 ec 28             	sub    $0x28,%esp
	struct Fd *fd;
	struct Pipe *p;
	int r;

	if ((r = fd_lookup(fdnum, &fd)) < 0)
  8015ac:	8d 45 f4             	lea    -0xc(%ebp),%eax
  8015af:	89 44 24 04          	mov    %eax,0x4(%esp)
  8015b3:	8b 45 08             	mov    0x8(%ebp),%eax
  8015b6:	89 04 24             	mov    %eax,(%esp)
  8015b9:	e8 5f f0 ff ff       	call   80061d <fd_lookup>
  8015be:	85 c0                	test   %eax,%eax
  8015c0:	78 15                	js     8015d7 <pipeisclosed+0x31>
		return r;
	p = (struct Pipe*) fd2data(fd);
  8015c2:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8015c5:	89 04 24             	mov    %eax,(%esp)
  8015c8:	e8 c3 ef ff ff       	call   800590 <fd2data>
	return _pipeisclosed(fd, p);
  8015cd:	89 c2                	mov    %eax,%edx
  8015cf:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8015d2:	e8 3b fe ff ff       	call   801412 <_pipeisclosed>
}
  8015d7:	c9                   	leave  
  8015d8:	c3                   	ret    

008015d9 <pipe>:
	uint8_t p_buf[PIPEBUFSIZ];	// data buffer
};

int
pipe(int pfd[2])
{
  8015d9:	55                   	push   %ebp
  8015da:	89 e5                	mov    %esp,%ebp
  8015dc:	83 ec 48             	sub    $0x48,%esp
  8015df:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  8015e2:	89 75 f8             	mov    %esi,-0x8(%ebp)
  8015e5:	89 7d fc             	mov    %edi,-0x4(%ebp)
  8015e8:	8b 7d 08             	mov    0x8(%ebp),%edi
	int r;
	struct Fd *fd0, *fd1;
	void *va;

	// allocate the file descriptor table entries
	if ((r = fd_alloc(&fd0)) < 0
  8015eb:	8d 45 e4             	lea    -0x1c(%ebp),%eax
  8015ee:	89 04 24             	mov    %eax,(%esp)
  8015f1:	e8 b5 ef ff ff       	call   8005ab <fd_alloc>
  8015f6:	89 c3                	mov    %eax,%ebx
  8015f8:	85 c0                	test   %eax,%eax
  8015fa:	0f 88 42 01 00 00    	js     801742 <pipe+0x169>
	    || (r = sys_page_alloc(0, fd0, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  801600:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  801607:	00 
  801608:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  80160b:	89 44 24 04          	mov    %eax,0x4(%esp)
  80160f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801616:	e8 37 ee ff ff       	call   800452 <sys_page_alloc>
  80161b:	89 c3                	mov    %eax,%ebx
	int r;
	struct Fd *fd0, *fd1;
	void *va;

	// allocate the file descriptor table entries
	if ((r = fd_alloc(&fd0)) < 0
  80161d:	85 c0                	test   %eax,%eax
  80161f:	0f 88 1d 01 00 00    	js     801742 <pipe+0x169>
	    || (r = sys_page_alloc(0, fd0, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
		goto err;

	if ((r = fd_alloc(&fd1)) < 0
  801625:	8d 45 e0             	lea    -0x20(%ebp),%eax
  801628:	89 04 24             	mov    %eax,(%esp)
  80162b:	e8 7b ef ff ff       	call   8005ab <fd_alloc>
  801630:	89 c3                	mov    %eax,%ebx
  801632:	85 c0                	test   %eax,%eax
  801634:	0f 88 f5 00 00 00    	js     80172f <pipe+0x156>
	    || (r = sys_page_alloc(0, fd1, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  80163a:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  801641:	00 
  801642:	8b 45 e0             	mov    -0x20(%ebp),%eax
  801645:	89 44 24 04          	mov    %eax,0x4(%esp)
  801649:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801650:	e8 fd ed ff ff       	call   800452 <sys_page_alloc>
  801655:	89 c3                	mov    %eax,%ebx
	// allocate the file descriptor table entries
	if ((r = fd_alloc(&fd0)) < 0
	    || (r = sys_page_alloc(0, fd0, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
		goto err;

	if ((r = fd_alloc(&fd1)) < 0
  801657:	85 c0                	test   %eax,%eax
  801659:	0f 88 d0 00 00 00    	js     80172f <pipe+0x156>
	    || (r = sys_page_alloc(0, fd1, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
		goto err1;

	// allocate the pipe structure as first data page in both
	va = fd2data(fd0);
  80165f:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801662:	89 04 24             	mov    %eax,(%esp)
  801665:	e8 26 ef ff ff       	call   800590 <fd2data>
  80166a:	89 c6                	mov    %eax,%esi
	if ((r = sys_page_alloc(0, va, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  80166c:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  801673:	00 
  801674:	89 44 24 04          	mov    %eax,0x4(%esp)
  801678:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80167f:	e8 ce ed ff ff       	call   800452 <sys_page_alloc>
  801684:	89 c3                	mov    %eax,%ebx
  801686:	85 c0                	test   %eax,%eax
  801688:	0f 88 8e 00 00 00    	js     80171c <pipe+0x143>
		goto err2;
	if ((r = sys_page_map(0, va, 0, fd2data(fd1), PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  80168e:	8b 45 e0             	mov    -0x20(%ebp),%eax
  801691:	89 04 24             	mov    %eax,(%esp)
  801694:	e8 f7 ee ff ff       	call   800590 <fd2data>
  801699:	c7 44 24 10 07 04 00 	movl   $0x407,0x10(%esp)
  8016a0:	00 
  8016a1:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8016a5:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  8016ac:	00 
  8016ad:	89 74 24 04          	mov    %esi,0x4(%esp)
  8016b1:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8016b8:	e8 37 ed ff ff       	call   8003f4 <sys_page_map>
  8016bd:	89 c3                	mov    %eax,%ebx
  8016bf:	85 c0                	test   %eax,%eax
  8016c1:	78 49                	js     80170c <pipe+0x133>
		goto err3;

	// set up fd structures
	fd0->fd_dev_id = devpipe.dev_id;
  8016c3:	b8 3c 60 80 00       	mov    $0x80603c,%eax
  8016c8:	8b 08                	mov    (%eax),%ecx
  8016ca:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  8016cd:	89 0a                	mov    %ecx,(%edx)
	fd0->fd_omode = O_RDONLY;
  8016cf:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  8016d2:	c7 42 08 00 00 00 00 	movl   $0x0,0x8(%edx)

	fd1->fd_dev_id = devpipe.dev_id;
  8016d9:	8b 10                	mov    (%eax),%edx
  8016db:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8016de:	89 10                	mov    %edx,(%eax)
	fd1->fd_omode = O_WRONLY;
  8016e0:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8016e3:	c7 40 08 01 00 00 00 	movl   $0x1,0x8(%eax)

	if (debug)
		cprintf("[%08x] pipecreate %08x\n", env->env_id, vpt[VPN(va)]);

	pfd[0] = fd2num(fd0);
  8016ea:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  8016ed:	89 04 24             	mov    %eax,(%esp)
  8016f0:	e8 8b ee ff ff       	call   800580 <fd2num>
  8016f5:	89 07                	mov    %eax,(%edi)
	pfd[1] = fd2num(fd1);
  8016f7:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8016fa:	89 04 24             	mov    %eax,(%esp)
  8016fd:	e8 7e ee ff ff       	call   800580 <fd2num>
  801702:	89 47 04             	mov    %eax,0x4(%edi)
  801705:	bb 00 00 00 00       	mov    $0x0,%ebx
	return 0;
  80170a:	eb 36                	jmp    801742 <pipe+0x169>

    err3:
	sys_page_unmap(0, va);
  80170c:	89 74 24 04          	mov    %esi,0x4(%esp)
  801710:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801717:	e8 7a ec ff ff       	call   800396 <sys_page_unmap>
    err2:
	sys_page_unmap(0, fd1);
  80171c:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80171f:	89 44 24 04          	mov    %eax,0x4(%esp)
  801723:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80172a:	e8 67 ec ff ff       	call   800396 <sys_page_unmap>
    err1:
	sys_page_unmap(0, fd0);
  80172f:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801732:	89 44 24 04          	mov    %eax,0x4(%esp)
  801736:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80173d:	e8 54 ec ff ff       	call   800396 <sys_page_unmap>
    err:
	return r;
}
  801742:	89 d8                	mov    %ebx,%eax
  801744:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  801747:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80174a:	8b 7d fc             	mov    -0x4(%ebp),%edi
  80174d:	89 ec                	mov    %ebp,%esp
  80174f:	5d                   	pop    %ebp
  801750:	c3                   	ret    
	...

00801760 <devcons_close>:
	return tot;
}

static int
devcons_close(struct Fd *fd)
{
  801760:	55                   	push   %ebp
  801761:	89 e5                	mov    %esp,%ebp
	USED(fd);

	return 0;
}
  801763:	b8 00 00 00 00       	mov    $0x0,%eax
  801768:	5d                   	pop    %ebp
  801769:	c3                   	ret    

0080176a <devcons_stat>:

static int
devcons_stat(struct Fd *fd, struct Stat *stat)
{
  80176a:	55                   	push   %ebp
  80176b:	89 e5                	mov    %esp,%ebp
  80176d:	83 ec 18             	sub    $0x18,%esp
	strcpy(stat->st_name, "<cons>");
  801770:	c7 44 24 04 45 29 80 	movl   $0x802945,0x4(%esp)
  801777:	00 
  801778:	8b 45 0c             	mov    0xc(%ebp),%eax
  80177b:	89 04 24             	mov    %eax,(%esp)
  80177e:	e8 27 09 00 00       	call   8020aa <strcpy>
	return 0;
}
  801783:	b8 00 00 00 00       	mov    $0x0,%eax
  801788:	c9                   	leave  
  801789:	c3                   	ret    

0080178a <devcons_write>:
	return 1;
}

static ssize_t
devcons_write(struct Fd *fd, const void *vbuf, size_t n)
{
  80178a:	55                   	push   %ebp
  80178b:	89 e5                	mov    %esp,%ebp
  80178d:	57                   	push   %edi
  80178e:	56                   	push   %esi
  80178f:	53                   	push   %ebx
  801790:	81 ec 9c 00 00 00    	sub    $0x9c,%esp
	int tot, m;
	char buf[128];

	// mistake: have to nul-terminate arg to sys_cputs, 
	// so we have to copy vbuf into buf in chunks and nul-terminate.
	for (tot = 0; tot < n; tot += m) {
  801796:	b8 00 00 00 00       	mov    $0x0,%eax
  80179b:	be 00 00 00 00       	mov    $0x0,%esi
  8017a0:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  8017a4:	74 41                	je     8017e7 <devcons_write+0x5d>
		m = n - tot;
		if (m > sizeof(buf) - 1)
			m = sizeof(buf) - 1;
		memmove(buf, (char*)vbuf + tot, m);
  8017a6:	8d bd 68 ff ff ff    	lea    -0x98(%ebp),%edi
	char buf[128];

	// mistake: have to nul-terminate arg to sys_cputs, 
	// so we have to copy vbuf into buf in chunks and nul-terminate.
	for (tot = 0; tot < n; tot += m) {
		m = n - tot;
  8017ac:	8b 5d 10             	mov    0x10(%ebp),%ebx
  8017af:	29 c3                	sub    %eax,%ebx
		if (m > sizeof(buf) - 1)
  8017b1:	81 fb 80 00 00 00    	cmp    $0x80,%ebx
  8017b7:	ba 7f 00 00 00       	mov    $0x7f,%edx
  8017bc:	0f 43 da             	cmovae %edx,%ebx
			m = sizeof(buf) - 1;
		memmove(buf, (char*)vbuf + tot, m);
  8017bf:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8017c3:	03 45 0c             	add    0xc(%ebp),%eax
  8017c6:	89 44 24 04          	mov    %eax,0x4(%esp)
  8017ca:	89 3c 24             	mov    %edi,(%esp)
  8017cd:	e8 93 0a 00 00       	call   802265 <memmove>
		sys_cputs(buf, m);
  8017d2:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  8017d6:	89 3c 24             	mov    %edi,(%esp)
  8017d9:	e8 0e e9 ff ff       	call   8000ec <sys_cputs>
	int tot, m;
	char buf[128];

	// mistake: have to nul-terminate arg to sys_cputs, 
	// so we have to copy vbuf into buf in chunks and nul-terminate.
	for (tot = 0; tot < n; tot += m) {
  8017de:	01 de                	add    %ebx,%esi
  8017e0:	89 f0                	mov    %esi,%eax
  8017e2:	3b 75 10             	cmp    0x10(%ebp),%esi
  8017e5:	72 c5                	jb     8017ac <devcons_write+0x22>
			m = sizeof(buf) - 1;
		memmove(buf, (char*)vbuf + tot, m);
		sys_cputs(buf, m);
	}
	return tot;
}
  8017e7:	89 f0                	mov    %esi,%eax
  8017e9:	81 c4 9c 00 00 00    	add    $0x9c,%esp
  8017ef:	5b                   	pop    %ebx
  8017f0:	5e                   	pop    %esi
  8017f1:	5f                   	pop    %edi
  8017f2:	5d                   	pop    %ebp
  8017f3:	c3                   	ret    

008017f4 <cputchar>:
#include <inc/string.h>
#include <inc/lib.h>

void
cputchar(int ch)
{
  8017f4:	55                   	push   %ebp
  8017f5:	89 e5                	mov    %esp,%ebp
  8017f7:	83 ec 28             	sub    $0x28,%esp
	char c = ch;
  8017fa:	8b 45 08             	mov    0x8(%ebp),%eax
  8017fd:	88 45 f7             	mov    %al,-0x9(%ebp)

	// Unlike standard Unix's putchar,
	// the cputchar function _always_ outputs to the system console.
	sys_cputs(&c, 1);
  801800:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
  801807:	00 
  801808:	8d 45 f7             	lea    -0x9(%ebp),%eax
  80180b:	89 04 24             	mov    %eax,(%esp)
  80180e:	e8 d9 e8 ff ff       	call   8000ec <sys_cputs>
}
  801813:	c9                   	leave  
  801814:	c3                   	ret    

00801815 <devcons_read>:
	return fd2num(fd);
}

static ssize_t
devcons_read(struct Fd *fd, void *vbuf, size_t n)
{
  801815:	55                   	push   %ebp
  801816:	89 e5                	mov    %esp,%ebp
  801818:	83 ec 08             	sub    $0x8,%esp
	int c;

	if (n == 0)
  80181b:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  80181f:	75 07                	jne    801828 <devcons_read+0x13>
  801821:	eb 2d                	jmp    801850 <devcons_read+0x3b>
		return 0;
	while ((c = sys_cgetc()) == 0)
		sys_yield();
  801823:	e8 89 ec ff ff       	call   8004b1 <sys_yield>
{
	int c;

	if (n == 0)
		return 0;
	while ((c = sys_cgetc()) == 0)
  801828:	90                   	nop
  801829:	8d b4 26 00 00 00 00 	lea    0x0(%esi,%eiz,1),%esi
  801830:	e8 83 e8 ff ff       	call   8000b8 <sys_cgetc>
  801835:	85 c0                	test   %eax,%eax
  801837:	74 ea                	je     801823 <devcons_read+0xe>
  801839:	89 c2                	mov    %eax,%edx
		sys_yield();
	if (c < 0)
  80183b:	85 c0                	test   %eax,%eax
  80183d:	78 16                	js     801855 <devcons_read+0x40>
		return c;
	if (c == 0x04)	// ctl-d is eof
  80183f:	83 f8 04             	cmp    $0x4,%eax
  801842:	74 0c                	je     801850 <devcons_read+0x3b>
		return 0;
	*(char*)vbuf = c;
  801844:	8b 45 0c             	mov    0xc(%ebp),%eax
  801847:	88 10                	mov    %dl,(%eax)
  801849:	b8 01 00 00 00       	mov    $0x1,%eax
	return 1;
  80184e:	eb 05                	jmp    801855 <devcons_read+0x40>
  801850:	b8 00 00 00 00       	mov    $0x0,%eax
}
  801855:	c9                   	leave  
  801856:	c3                   	ret    

00801857 <opencons>:
	return fd->fd_dev_id == devcons.dev_id;
}

int
opencons(void)
{
  801857:	55                   	push   %ebp
  801858:	89 e5                	mov    %esp,%ebp
  80185a:	83 ec 28             	sub    $0x28,%esp
	int r;
	struct Fd* fd;

	if ((r = fd_alloc(&fd)) < 0)
  80185d:	8d 45 f4             	lea    -0xc(%ebp),%eax
  801860:	89 04 24             	mov    %eax,(%esp)
  801863:	e8 43 ed ff ff       	call   8005ab <fd_alloc>
  801868:	85 c0                	test   %eax,%eax
  80186a:	78 3f                	js     8018ab <opencons+0x54>
		return r;
	if ((r = sys_page_alloc(0, fd, PTE_P|PTE_U|PTE_W|PTE_SHARE)) < 0)
  80186c:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  801873:	00 
  801874:	8b 45 f4             	mov    -0xc(%ebp),%eax
  801877:	89 44 24 04          	mov    %eax,0x4(%esp)
  80187b:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801882:	e8 cb eb ff ff       	call   800452 <sys_page_alloc>
  801887:	85 c0                	test   %eax,%eax
  801889:	78 20                	js     8018ab <opencons+0x54>
		return r;
	fd->fd_dev_id = devcons.dev_id;
  80188b:	8b 15 58 60 80 00    	mov    0x806058,%edx
  801891:	8b 45 f4             	mov    -0xc(%ebp),%eax
  801894:	89 10                	mov    %edx,(%eax)
	fd->fd_omode = O_RDWR;
  801896:	8b 45 f4             	mov    -0xc(%ebp),%eax
  801899:	c7 40 08 02 00 00 00 	movl   $0x2,0x8(%eax)
	return fd2num(fd);
  8018a0:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8018a3:	89 04 24             	mov    %eax,(%esp)
  8018a6:	e8 d5 ec ff ff       	call   800580 <fd2num>
}
  8018ab:	c9                   	leave  
  8018ac:	c3                   	ret    

008018ad <iscons>:
	.dev_stat =	devcons_stat
};

int
iscons(int fdnum)
{
  8018ad:	55                   	push   %ebp
  8018ae:	89 e5                	mov    %esp,%ebp
  8018b0:	83 ec 28             	sub    $0x28,%esp
	int r;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0)
  8018b3:	8d 45 f4             	lea    -0xc(%ebp),%eax
  8018b6:	89 44 24 04          	mov    %eax,0x4(%esp)
  8018ba:	8b 45 08             	mov    0x8(%ebp),%eax
  8018bd:	89 04 24             	mov    %eax,(%esp)
  8018c0:	e8 58 ed ff ff       	call   80061d <fd_lookup>
  8018c5:	85 c0                	test   %eax,%eax
  8018c7:	78 11                	js     8018da <iscons+0x2d>
		return r;
	return fd->fd_dev_id == devcons.dev_id;
  8018c9:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8018cc:	8b 00                	mov    (%eax),%eax
  8018ce:	3b 05 58 60 80 00    	cmp    0x806058,%eax
  8018d4:	0f 94 c0             	sete   %al
  8018d7:	0f b6 c0             	movzbl %al,%eax
}
  8018da:	c9                   	leave  
  8018db:	c3                   	ret    

008018dc <getchar>:
	sys_cputs(&c, 1);
}

int
getchar(void)
{
  8018dc:	55                   	push   %ebp
  8018dd:	89 e5                	mov    %esp,%ebp
  8018df:	83 ec 28             	sub    $0x28,%esp
	int r;

	// JOS does, however, support standard _input_ redirection,
	// allowing the user to redirect script files to the shell and such.
	// getchar() reads a character from file descriptor 0.
	r = read(0, &c, 1);
  8018e2:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
  8018e9:	00 
  8018ea:	8d 45 f7             	lea    -0x9(%ebp),%eax
  8018ed:	89 44 24 04          	mov    %eax,0x4(%esp)
  8018f1:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8018f8:	e8 86 ef ff ff       	call   800883 <read>
	if (r < 0)
  8018fd:	85 c0                	test   %eax,%eax
  8018ff:	78 0f                	js     801910 <getchar+0x34>
		return r;
	if (r < 1)
  801901:	85 c0                	test   %eax,%eax
  801903:	7f 07                	jg     80190c <getchar+0x30>
  801905:	b8 f8 ff ff ff       	mov    $0xfffffff8,%eax
  80190a:	eb 04                	jmp    801910 <getchar+0x34>
		return -E_EOF;
	return c;
  80190c:	0f b6 45 f7          	movzbl -0x9(%ebp),%eax
}
  801910:	c9                   	leave  
  801911:	c3                   	ret    
	...

00801914 <_panic>:
 * It prints "panic: <message>", then causes a breakpoint exception,
 * which causes JOS to enter the JOS kernel monitor.
 */
void
_panic(const char *file, int line, const char *fmt,...)
{
  801914:	55                   	push   %ebp
  801915:	89 e5                	mov    %esp,%ebp
  801917:	53                   	push   %ebx
  801918:	83 ec 14             	sub    $0x14,%esp
 * Panic is called on unresolvable fatal errors.
 * It prints "panic: <message>", then causes a breakpoint exception,
 * which causes JOS to enter the JOS kernel monitor.
 */
void
_panic(const char *file, int line, const char *fmt,...)
  80191b:	8d 5d 14             	lea    0x14(%ebp),%ebx
	va_list ap;

	va_start(ap, fmt);

	// Print the panic message
	if (argv0)
  80191e:	a1 78 60 80 00       	mov    0x806078,%eax
  801923:	85 c0                	test   %eax,%eax
  801925:	74 10                	je     801937 <_panic+0x23>
		cprintf("%s: ", argv0);
  801927:	89 44 24 04          	mov    %eax,0x4(%esp)
  80192b:	c7 04 24 51 29 80 00 	movl   $0x802951,(%esp)
  801932:	e8 a2 00 00 00       	call   8019d9 <cprintf>
	cprintf("user panic in %s at %s:%d: ", binaryname, file, line);
  801937:	8b 45 0c             	mov    0xc(%ebp),%eax
  80193a:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80193e:	8b 45 08             	mov    0x8(%ebp),%eax
  801941:	89 44 24 08          	mov    %eax,0x8(%esp)
  801945:	a1 00 60 80 00       	mov    0x806000,%eax
  80194a:	89 44 24 04          	mov    %eax,0x4(%esp)
  80194e:	c7 04 24 56 29 80 00 	movl   $0x802956,(%esp)
  801955:	e8 7f 00 00 00       	call   8019d9 <cprintf>
	vcprintf(fmt, ap);
  80195a:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  80195e:	8b 45 10             	mov    0x10(%ebp),%eax
  801961:	89 04 24             	mov    %eax,(%esp)
  801964:	e8 0f 00 00 00       	call   801978 <vcprintf>
	cprintf("\n");
  801969:	c7 04 24 3e 29 80 00 	movl   $0x80293e,(%esp)
  801970:	e8 64 00 00 00       	call   8019d9 <cprintf>

	// Cause a breakpoint exception
	while (1)
		asm volatile("int3");
  801975:	cc                   	int3   
  801976:	eb fd                	jmp    801975 <_panic+0x61>

00801978 <vcprintf>:
	b->cnt++;
}

int
vcprintf(const char *fmt, va_list ap)
{
  801978:	55                   	push   %ebp
  801979:	89 e5                	mov    %esp,%ebp
  80197b:	81 ec 28 01 00 00    	sub    $0x128,%esp
	struct printbuf b;

	b.idx = 0;
  801981:	c7 85 f0 fe ff ff 00 	movl   $0x0,-0x110(%ebp)
  801988:	00 00 00 
	b.cnt = 0;
  80198b:	c7 85 f4 fe ff ff 00 	movl   $0x0,-0x10c(%ebp)
  801992:	00 00 00 
	vprintfmt((void*)putch, &b, fmt, ap);
  801995:	8b 45 0c             	mov    0xc(%ebp),%eax
  801998:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80199c:	8b 45 08             	mov    0x8(%ebp),%eax
  80199f:	89 44 24 08          	mov    %eax,0x8(%esp)
  8019a3:	8d 85 f0 fe ff ff    	lea    -0x110(%ebp),%eax
  8019a9:	89 44 24 04          	mov    %eax,0x4(%esp)
  8019ad:	c7 04 24 f3 19 80 00 	movl   $0x8019f3,(%esp)
  8019b4:	e8 d4 01 00 00       	call   801b8d <vprintfmt>
	sys_cputs(b.buf, b.idx);
  8019b9:	8b 85 f0 fe ff ff    	mov    -0x110(%ebp),%eax
  8019bf:	89 44 24 04          	mov    %eax,0x4(%esp)
  8019c3:	8d 85 f8 fe ff ff    	lea    -0x108(%ebp),%eax
  8019c9:	89 04 24             	mov    %eax,(%esp)
  8019cc:	e8 1b e7 ff ff       	call   8000ec <sys_cputs>

	return b.cnt;
}
  8019d1:	8b 85 f4 fe ff ff    	mov    -0x10c(%ebp),%eax
  8019d7:	c9                   	leave  
  8019d8:	c3                   	ret    

008019d9 <cprintf>:

int
cprintf(const char *fmt, ...)
{
  8019d9:	55                   	push   %ebp
  8019da:	89 e5                	mov    %esp,%ebp
  8019dc:	83 ec 18             	sub    $0x18,%esp

	return b.cnt;
}

int
cprintf(const char *fmt, ...)
  8019df:	8d 45 0c             	lea    0xc(%ebp),%eax
{
	va_list ap;
	int cnt;

	va_start(ap, fmt);
	cnt = vcprintf(fmt, ap);
  8019e2:	89 44 24 04          	mov    %eax,0x4(%esp)
  8019e6:	8b 45 08             	mov    0x8(%ebp),%eax
  8019e9:	89 04 24             	mov    %eax,(%esp)
  8019ec:	e8 87 ff ff ff       	call   801978 <vcprintf>
	va_end(ap);

	return cnt;
}
  8019f1:	c9                   	leave  
  8019f2:	c3                   	ret    

008019f3 <putch>:
};


static void
putch(int ch, struct printbuf *b)
{
  8019f3:	55                   	push   %ebp
  8019f4:	89 e5                	mov    %esp,%ebp
  8019f6:	53                   	push   %ebx
  8019f7:	83 ec 14             	sub    $0x14,%esp
  8019fa:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	b->buf[b->idx++] = ch;
  8019fd:	8b 03                	mov    (%ebx),%eax
  8019ff:	8b 55 08             	mov    0x8(%ebp),%edx
  801a02:	88 54 03 08          	mov    %dl,0x8(%ebx,%eax,1)
  801a06:	83 c0 01             	add    $0x1,%eax
  801a09:	89 03                	mov    %eax,(%ebx)
	if (b->idx == 256-1) {
  801a0b:	3d ff 00 00 00       	cmp    $0xff,%eax
  801a10:	75 19                	jne    801a2b <putch+0x38>
		sys_cputs(b->buf, b->idx);
  801a12:	c7 44 24 04 ff 00 00 	movl   $0xff,0x4(%esp)
  801a19:	00 
  801a1a:	8d 43 08             	lea    0x8(%ebx),%eax
  801a1d:	89 04 24             	mov    %eax,(%esp)
  801a20:	e8 c7 e6 ff ff       	call   8000ec <sys_cputs>
		b->idx = 0;
  801a25:	c7 03 00 00 00 00    	movl   $0x0,(%ebx)
	}
	b->cnt++;
  801a2b:	83 43 04 01          	addl   $0x1,0x4(%ebx)
}
  801a2f:	83 c4 14             	add    $0x14,%esp
  801a32:	5b                   	pop    %ebx
  801a33:	5d                   	pop    %ebp
  801a34:	c3                   	ret    
	...

00801a40 <printnum>:
 * using specified putch function and associated pointer putdat.
 */
static void
printnum(void (*putch)(int, void*), void *putdat,
	 unsigned long long num, unsigned base, int width, int padc)
{
  801a40:	55                   	push   %ebp
  801a41:	89 e5                	mov    %esp,%ebp
  801a43:	57                   	push   %edi
  801a44:	56                   	push   %esi
  801a45:	53                   	push   %ebx
  801a46:	83 ec 4c             	sub    $0x4c,%esp
  801a49:	89 45 e4             	mov    %eax,-0x1c(%ebp)
  801a4c:	89 d6                	mov    %edx,%esi
  801a4e:	8b 45 08             	mov    0x8(%ebp),%eax
  801a51:	89 45 d8             	mov    %eax,-0x28(%ebp)
  801a54:	8b 55 0c             	mov    0xc(%ebp),%edx
  801a57:	89 55 e0             	mov    %edx,-0x20(%ebp)
  801a5a:	8b 45 10             	mov    0x10(%ebp),%eax
  801a5d:	8b 5d 14             	mov    0x14(%ebp),%ebx
  801a60:	8b 7d 18             	mov    0x18(%ebp),%edi
	// first recursively print all preceding (more significant) digits
	if (num >= base) {
  801a63:	89 45 dc             	mov    %eax,-0x24(%ebp)
  801a66:	b9 00 00 00 00       	mov    $0x0,%ecx
  801a6b:	39 d1                	cmp    %edx,%ecx
  801a6d:	72 15                	jb     801a84 <printnum+0x44>
  801a6f:	77 07                	ja     801a78 <printnum+0x38>
  801a71:	8b 55 d8             	mov    -0x28(%ebp),%edx
  801a74:	39 d0                	cmp    %edx,%eax
  801a76:	76 0c                	jbe    801a84 <printnum+0x44>
		printnum(putch, putdat, num / base, base, width - 1, padc);
	} else {
		// print any needed pad characters before first digit
		while (--width > 0)
  801a78:	83 eb 01             	sub    $0x1,%ebx
  801a7b:	85 db                	test   %ebx,%ebx
  801a7d:	8d 76 00             	lea    0x0(%esi),%esi
  801a80:	7f 61                	jg     801ae3 <printnum+0xa3>
  801a82:	eb 70                	jmp    801af4 <printnum+0xb4>
printnum(void (*putch)(int, void*), void *putdat,
	 unsigned long long num, unsigned base, int width, int padc)
{
	// first recursively print all preceding (more significant) digits
	if (num >= base) {
		printnum(putch, putdat, num / base, base, width - 1, padc);
  801a84:	89 7c 24 10          	mov    %edi,0x10(%esp)
  801a88:	83 eb 01             	sub    $0x1,%ebx
  801a8b:	89 5c 24 0c          	mov    %ebx,0xc(%esp)
  801a8f:	89 44 24 08          	mov    %eax,0x8(%esp)
  801a93:	8b 4c 24 08          	mov    0x8(%esp),%ecx
  801a97:	8b 5c 24 0c          	mov    0xc(%esp),%ebx
  801a9b:	89 4d d0             	mov    %ecx,-0x30(%ebp)
  801a9e:	89 5d d4             	mov    %ebx,-0x2c(%ebp)
  801aa1:	8b 5d dc             	mov    -0x24(%ebp),%ebx
  801aa4:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  801aa8:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  801aaf:	00 
  801ab0:	8b 45 d8             	mov    -0x28(%ebp),%eax
  801ab3:	89 04 24             	mov    %eax,(%esp)
  801ab6:	8b 55 e0             	mov    -0x20(%ebp),%edx
  801ab9:	89 54 24 04          	mov    %edx,0x4(%esp)
  801abd:	e8 be 0a 00 00       	call   802580 <__udivdi3>
  801ac2:	8b 4d d0             	mov    -0x30(%ebp),%ecx
  801ac5:	8b 5d d4             	mov    -0x2c(%ebp),%ebx
  801ac8:	89 4c 24 08          	mov    %ecx,0x8(%esp)
  801acc:	89 5c 24 0c          	mov    %ebx,0xc(%esp)
  801ad0:	89 04 24             	mov    %eax,(%esp)
  801ad3:	89 54 24 04          	mov    %edx,0x4(%esp)
  801ad7:	89 f2                	mov    %esi,%edx
  801ad9:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801adc:	e8 5f ff ff ff       	call   801a40 <printnum>
  801ae1:	eb 11                	jmp    801af4 <printnum+0xb4>
	} else {
		// print any needed pad characters before first digit
		while (--width > 0)
			putch(padc, putdat);
  801ae3:	89 74 24 04          	mov    %esi,0x4(%esp)
  801ae7:	89 3c 24             	mov    %edi,(%esp)
  801aea:	ff 55 e4             	call   *-0x1c(%ebp)
	// first recursively print all preceding (more significant) digits
	if (num >= base) {
		printnum(putch, putdat, num / base, base, width - 1, padc);
	} else {
		// print any needed pad characters before first digit
		while (--width > 0)
  801aed:	83 eb 01             	sub    $0x1,%ebx
  801af0:	85 db                	test   %ebx,%ebx
  801af2:	7f ef                	jg     801ae3 <printnum+0xa3>
			putch(padc, putdat);
	}

	// then print this (the least significant) digit
	putch("0123456789abcdef"[num % base], putdat);
  801af4:	89 74 24 04          	mov    %esi,0x4(%esp)
  801af8:	8b 74 24 04          	mov    0x4(%esp),%esi
  801afc:	8b 45 dc             	mov    -0x24(%ebp),%eax
  801aff:	89 44 24 08          	mov    %eax,0x8(%esp)
  801b03:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  801b0a:	00 
  801b0b:	8b 55 d8             	mov    -0x28(%ebp),%edx
  801b0e:	89 14 24             	mov    %edx,(%esp)
  801b11:	8b 4d e0             	mov    -0x20(%ebp),%ecx
  801b14:	89 4c 24 04          	mov    %ecx,0x4(%esp)
  801b18:	e8 93 0b 00 00       	call   8026b0 <__umoddi3>
  801b1d:	89 74 24 04          	mov    %esi,0x4(%esp)
  801b21:	0f be 80 72 29 80 00 	movsbl 0x802972(%eax),%eax
  801b28:	89 04 24             	mov    %eax,(%esp)
  801b2b:	ff 55 e4             	call   *-0x1c(%ebp)
}
  801b2e:	83 c4 4c             	add    $0x4c,%esp
  801b31:	5b                   	pop    %ebx
  801b32:	5e                   	pop    %esi
  801b33:	5f                   	pop    %edi
  801b34:	5d                   	pop    %ebp
  801b35:	c3                   	ret    

00801b36 <getuint>:

// Get an unsigned int of various possible sizes from a varargs list,
// depending on the lflag parameter.
static unsigned long long
getuint(va_list *ap, int lflag)
{
  801b36:	55                   	push   %ebp
  801b37:	89 e5                	mov    %esp,%ebp
	if (lflag >= 2)
  801b39:	83 fa 01             	cmp    $0x1,%edx
  801b3c:	7e 0e                	jle    801b4c <getuint+0x16>
		return va_arg(*ap, unsigned long long);
  801b3e:	8b 10                	mov    (%eax),%edx
  801b40:	8d 4a 08             	lea    0x8(%edx),%ecx
  801b43:	89 08                	mov    %ecx,(%eax)
  801b45:	8b 02                	mov    (%edx),%eax
  801b47:	8b 52 04             	mov    0x4(%edx),%edx
  801b4a:	eb 22                	jmp    801b6e <getuint+0x38>
	else if (lflag)
  801b4c:	85 d2                	test   %edx,%edx
  801b4e:	74 10                	je     801b60 <getuint+0x2a>
		return va_arg(*ap, unsigned long);
  801b50:	8b 10                	mov    (%eax),%edx
  801b52:	8d 4a 04             	lea    0x4(%edx),%ecx
  801b55:	89 08                	mov    %ecx,(%eax)
  801b57:	8b 02                	mov    (%edx),%eax
  801b59:	ba 00 00 00 00       	mov    $0x0,%edx
  801b5e:	eb 0e                	jmp    801b6e <getuint+0x38>
	else
		return va_arg(*ap, unsigned int);
  801b60:	8b 10                	mov    (%eax),%edx
  801b62:	8d 4a 04             	lea    0x4(%edx),%ecx
  801b65:	89 08                	mov    %ecx,(%eax)
  801b67:	8b 02                	mov    (%edx),%eax
  801b69:	ba 00 00 00 00       	mov    $0x0,%edx
}
  801b6e:	5d                   	pop    %ebp
  801b6f:	c3                   	ret    

00801b70 <sprintputch>:
	int cnt;
};

static void
sprintputch(int ch, struct sprintbuf *b)
{
  801b70:	55                   	push   %ebp
  801b71:	89 e5                	mov    %esp,%ebp
  801b73:	8b 45 0c             	mov    0xc(%ebp),%eax
	b->cnt++;
  801b76:	83 40 08 01          	addl   $0x1,0x8(%eax)
	if (b->buf < b->ebuf)
  801b7a:	8b 10                	mov    (%eax),%edx
  801b7c:	3b 50 04             	cmp    0x4(%eax),%edx
  801b7f:	73 0a                	jae    801b8b <sprintputch+0x1b>
		*b->buf++ = ch;
  801b81:	8b 4d 08             	mov    0x8(%ebp),%ecx
  801b84:	88 0a                	mov    %cl,(%edx)
  801b86:	83 c2 01             	add    $0x1,%edx
  801b89:	89 10                	mov    %edx,(%eax)
}
  801b8b:	5d                   	pop    %ebp
  801b8c:	c3                   	ret    

00801b8d <vprintfmt>:
// Main function to format and print a string.
void printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...);

void
vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list ap)
{
  801b8d:	55                   	push   %ebp
  801b8e:	89 e5                	mov    %esp,%ebp
  801b90:	57                   	push   %edi
  801b91:	56                   	push   %esi
  801b92:	53                   	push   %ebx
  801b93:	83 ec 5c             	sub    $0x5c,%esp
  801b96:	8b 7d 08             	mov    0x8(%ebp),%edi
  801b99:	8b 75 0c             	mov    0xc(%ebp),%esi
  801b9c:	8b 5d 10             	mov    0x10(%ebp),%ebx
		case '#':
			altflag = 1;
			goto reswitch;

		process_precision:
			if (width < 0)
  801b9f:	c7 45 c8 ff ff ff ff 	movl   $0xffffffff,-0x38(%ebp)
  801ba6:	eb 11                	jmp    801bb9 <vprintfmt+0x2c>
	int base, lflag, width, precision, altflag;
	char padc;

	while (1) {
		while ((ch = *(unsigned char *) fmt++) != '%') {
			if (ch == '\0')
  801ba8:	85 c0                	test   %eax,%eax
  801baa:	0f 84 f9 03 00 00    	je     801fa9 <vprintfmt+0x41c>
				return;
			putch(ch, putdat);
  801bb0:	89 74 24 04          	mov    %esi,0x4(%esp)
  801bb4:	89 04 24             	mov    %eax,(%esp)
  801bb7:	ff d7                	call   *%edi
	unsigned long long num;
	int base, lflag, width, precision, altflag;
	char padc;

	while (1) {
		while ((ch = *(unsigned char *) fmt++) != '%') {
  801bb9:	0f b6 03             	movzbl (%ebx),%eax
  801bbc:	83 c3 01             	add    $0x1,%ebx
  801bbf:	83 f8 25             	cmp    $0x25,%eax
  801bc2:	75 e4                	jne    801ba8 <vprintfmt+0x1b>
  801bc4:	c6 45 d4 20          	movb   $0x20,-0x2c(%ebp)
  801bc8:	c7 45 d8 00 00 00 00 	movl   $0x0,-0x28(%ebp)
  801bcf:	c7 45 d0 ff ff ff ff 	movl   $0xffffffff,-0x30(%ebp)
  801bd6:	c7 45 e4 ff ff ff ff 	movl   $0xffffffff,-0x1c(%ebp)
  801bdd:	b9 00 00 00 00       	mov    $0x0,%ecx
  801be2:	eb 06                	jmp    801bea <vprintfmt+0x5d>
  801be4:	c6 45 d4 2d          	movb   $0x2d,-0x2c(%ebp)
  801be8:	89 c3                	mov    %eax,%ebx
		width = -1;
		precision = -1;
		lflag = 0;
		altflag = 0;
	reswitch:
		switch (ch = *(unsigned char *) fmt++) {
  801bea:	0f b6 13             	movzbl (%ebx),%edx
  801bed:	0f b6 c2             	movzbl %dl,%eax
  801bf0:	89 45 e0             	mov    %eax,-0x20(%ebp)
  801bf3:	8d 43 01             	lea    0x1(%ebx),%eax
  801bf6:	83 ea 23             	sub    $0x23,%edx
  801bf9:	80 fa 55             	cmp    $0x55,%dl
  801bfc:	0f 87 8a 03 00 00    	ja     801f8c <vprintfmt+0x3ff>
  801c02:	0f b6 d2             	movzbl %dl,%edx
  801c05:	ff 24 95 c0 2a 80 00 	jmp    *0x802ac0(,%edx,4)
  801c0c:	c6 45 d4 30          	movb   $0x30,-0x2c(%ebp)
  801c10:	eb d6                	jmp    801be8 <vprintfmt+0x5b>
		case '6':
		case '7':
		case '8':
		case '9':
			for (precision = 0; ; ++fmt) {
				precision = precision * 10 + ch - '0';
  801c12:	8b 55 e0             	mov    -0x20(%ebp),%edx
  801c15:	83 ea 30             	sub    $0x30,%edx
  801c18:	89 55 d0             	mov    %edx,-0x30(%ebp)
				ch = *fmt;
  801c1b:	0f be 10             	movsbl (%eax),%edx
				if (ch < '0' || ch > '9')
  801c1e:	8d 5a d0             	lea    -0x30(%edx),%ebx
  801c21:	83 fb 09             	cmp    $0x9,%ebx
  801c24:	77 54                	ja     801c7a <vprintfmt+0xed>
  801c26:	89 4d e0             	mov    %ecx,-0x20(%ebp)
  801c29:	8b 4d d0             	mov    -0x30(%ebp),%ecx
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			for (precision = 0; ; ++fmt) {
  801c2c:	83 c0 01             	add    $0x1,%eax
				precision = precision * 10 + ch - '0';
  801c2f:	8d 0c 89             	lea    (%ecx,%ecx,4),%ecx
  801c32:	8d 4c 4a d0          	lea    -0x30(%edx,%ecx,2),%ecx
				ch = *fmt;
  801c36:	0f be 10             	movsbl (%eax),%edx
				if (ch < '0' || ch > '9')
  801c39:	8d 5a d0             	lea    -0x30(%edx),%ebx
  801c3c:	83 fb 09             	cmp    $0x9,%ebx
  801c3f:	76 eb                	jbe    801c2c <vprintfmt+0x9f>
  801c41:	89 4d d0             	mov    %ecx,-0x30(%ebp)
  801c44:	8b 4d e0             	mov    -0x20(%ebp),%ecx
  801c47:	eb 31                	jmp    801c7a <vprintfmt+0xed>
					break;
			}
			goto process_precision;

		case '*':
			precision = va_arg(ap, int);
  801c49:	8b 55 14             	mov    0x14(%ebp),%edx
  801c4c:	8d 5a 04             	lea    0x4(%edx),%ebx
  801c4f:	89 5d 14             	mov    %ebx,0x14(%ebp)
  801c52:	8b 12                	mov    (%edx),%edx
  801c54:	89 55 d0             	mov    %edx,-0x30(%ebp)
			goto process_precision;
  801c57:	eb 21                	jmp    801c7a <vprintfmt+0xed>

		case '.':
			if (width < 0)
  801c59:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
  801c5d:	ba 00 00 00 00       	mov    $0x0,%edx
  801c62:	0f 49 55 e4          	cmovns -0x1c(%ebp),%edx
  801c66:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  801c69:	e9 7a ff ff ff       	jmp    801be8 <vprintfmt+0x5b>
  801c6e:	c7 45 d8 01 00 00 00 	movl   $0x1,-0x28(%ebp)
				width = 0;
			goto reswitch;

		case '#':
			altflag = 1;
			goto reswitch;
  801c75:	e9 6e ff ff ff       	jmp    801be8 <vprintfmt+0x5b>

		process_precision:
			if (width < 0)
  801c7a:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
  801c7e:	0f 89 64 ff ff ff    	jns    801be8 <vprintfmt+0x5b>
  801c84:	8b 55 d0             	mov    -0x30(%ebp),%edx
  801c87:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  801c8a:	8b 55 c8             	mov    -0x38(%ebp),%edx
  801c8d:	89 55 d0             	mov    %edx,-0x30(%ebp)
  801c90:	e9 53 ff ff ff       	jmp    801be8 <vprintfmt+0x5b>
				width = precision, precision = -1;
			goto reswitch;

		// long flag (doubled for long long)
		case 'l':
			lflag++;
  801c95:	83 c1 01             	add    $0x1,%ecx
			goto reswitch;
  801c98:	e9 4b ff ff ff       	jmp    801be8 <vprintfmt+0x5b>
  801c9d:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// character
		case 'c':
			putch(va_arg(ap, int), putdat);
  801ca0:	8b 45 14             	mov    0x14(%ebp),%eax
  801ca3:	8d 50 04             	lea    0x4(%eax),%edx
  801ca6:	89 55 14             	mov    %edx,0x14(%ebp)
  801ca9:	89 74 24 04          	mov    %esi,0x4(%esp)
  801cad:	8b 00                	mov    (%eax),%eax
  801caf:	89 04 24             	mov    %eax,(%esp)
  801cb2:	ff d7                	call   *%edi
  801cb4:	8b 5d cc             	mov    -0x34(%ebp),%ebx
			break;
  801cb7:	e9 fd fe ff ff       	jmp    801bb9 <vprintfmt+0x2c>
  801cbc:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// error message
		case 'e':
			err = va_arg(ap, int);
  801cbf:	8b 45 14             	mov    0x14(%ebp),%eax
  801cc2:	8d 50 04             	lea    0x4(%eax),%edx
  801cc5:	89 55 14             	mov    %edx,0x14(%ebp)
  801cc8:	8b 00                	mov    (%eax),%eax
  801cca:	89 c2                	mov    %eax,%edx
  801ccc:	c1 fa 1f             	sar    $0x1f,%edx
  801ccf:	31 d0                	xor    %edx,%eax
  801cd1:	29 d0                	sub    %edx,%eax
			if (err < 0)
				err = -err;
			if (err > MAXERROR || (p = error_string[err]) == NULL)
  801cd3:	83 f8 12             	cmp    $0x12,%eax
  801cd6:	7f 0b                	jg     801ce3 <vprintfmt+0x156>
  801cd8:	8b 14 85 20 2c 80 00 	mov    0x802c20(,%eax,4),%edx
  801cdf:	85 d2                	test   %edx,%edx
  801ce1:	75 20                	jne    801d03 <vprintfmt+0x176>
				printfmt(putch, putdat, "error %d", err);
  801ce3:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801ce7:	c7 44 24 08 83 29 80 	movl   $0x802983,0x8(%esp)
  801cee:	00 
  801cef:	89 74 24 04          	mov    %esi,0x4(%esp)
  801cf3:	89 3c 24             	mov    %edi,(%esp)
  801cf6:	e8 36 03 00 00       	call   802031 <printfmt>
  801cfb:	8b 5d cc             	mov    -0x34(%ebp),%ebx
		// error message
		case 'e':
			err = va_arg(ap, int);
			if (err < 0)
				err = -err;
			if (err > MAXERROR || (p = error_string[err]) == NULL)
  801cfe:	e9 b6 fe ff ff       	jmp    801bb9 <vprintfmt+0x2c>
				printfmt(putch, putdat, "error %d", err);
			else
				printfmt(putch, putdat, "%s", p);
  801d03:	89 54 24 0c          	mov    %edx,0xc(%esp)
  801d07:	c7 44 24 08 02 29 80 	movl   $0x802902,0x8(%esp)
  801d0e:	00 
  801d0f:	89 74 24 04          	mov    %esi,0x4(%esp)
  801d13:	89 3c 24             	mov    %edi,(%esp)
  801d16:	e8 16 03 00 00       	call   802031 <printfmt>
  801d1b:	8b 5d cc             	mov    -0x34(%ebp),%ebx
  801d1e:	e9 96 fe ff ff       	jmp    801bb9 <vprintfmt+0x2c>
  801d23:	89 45 cc             	mov    %eax,-0x34(%ebp)
  801d26:	89 c3                	mov    %eax,%ebx
  801d28:	8b 4d d0             	mov    -0x30(%ebp),%ecx
  801d2b:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801d2e:	89 45 c4             	mov    %eax,-0x3c(%ebp)
			break;

		// string
		case 's':
			if ((p = va_arg(ap, char *)) == NULL)
  801d31:	8b 45 14             	mov    0x14(%ebp),%eax
  801d34:	8d 50 04             	lea    0x4(%eax),%edx
  801d37:	89 55 14             	mov    %edx,0x14(%ebp)
  801d3a:	8b 00                	mov    (%eax),%eax
  801d3c:	89 45 e0             	mov    %eax,-0x20(%ebp)
  801d3f:	85 c0                	test   %eax,%eax
  801d41:	b8 8c 29 80 00       	mov    $0x80298c,%eax
  801d46:	0f 45 45 e0          	cmovne -0x20(%ebp),%eax
  801d4a:	89 45 e0             	mov    %eax,-0x20(%ebp)
				p = "(null)";
			if (width > 0 && padc != '-')
  801d4d:	83 7d c4 00          	cmpl   $0x0,-0x3c(%ebp)
  801d51:	7e 06                	jle    801d59 <vprintfmt+0x1cc>
  801d53:	80 7d d4 2d          	cmpb   $0x2d,-0x2c(%ebp)
  801d57:	75 13                	jne    801d6c <vprintfmt+0x1df>
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
  801d59:	8b 55 e0             	mov    -0x20(%ebp),%edx
  801d5c:	0f be 02             	movsbl (%edx),%eax
  801d5f:	85 c0                	test   %eax,%eax
  801d61:	0f 85 9b 00 00 00    	jne    801e02 <vprintfmt+0x275>
  801d67:	e9 88 00 00 00       	jmp    801df4 <vprintfmt+0x267>
		// string
		case 's':
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
  801d6c:	89 4c 24 04          	mov    %ecx,0x4(%esp)
  801d70:	8b 4d e0             	mov    -0x20(%ebp),%ecx
  801d73:	89 0c 24             	mov    %ecx,(%esp)
  801d76:	e8 00 03 00 00       	call   80207b <strnlen>
  801d7b:	8b 55 c4             	mov    -0x3c(%ebp),%edx
  801d7e:	29 c2                	sub    %eax,%edx
  801d80:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  801d83:	85 d2                	test   %edx,%edx
  801d85:	7e d2                	jle    801d59 <vprintfmt+0x1cc>
					putch(padc, putdat);
  801d87:	0f be 4d d4          	movsbl -0x2c(%ebp),%ecx
  801d8b:	89 4d d4             	mov    %ecx,-0x2c(%ebp)
  801d8e:	89 5d c4             	mov    %ebx,-0x3c(%ebp)
  801d91:	89 d3                	mov    %edx,%ebx
  801d93:	89 74 24 04          	mov    %esi,0x4(%esp)
  801d97:	8b 45 d4             	mov    -0x2c(%ebp),%eax
  801d9a:	89 04 24             	mov    %eax,(%esp)
  801d9d:	ff d7                	call   *%edi
		// string
		case 's':
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
  801d9f:	83 eb 01             	sub    $0x1,%ebx
  801da2:	85 db                	test   %ebx,%ebx
  801da4:	7f ed                	jg     801d93 <vprintfmt+0x206>
  801da6:	8b 5d c4             	mov    -0x3c(%ebp),%ebx
  801da9:	c7 45 e4 00 00 00 00 	movl   $0x0,-0x1c(%ebp)
  801db0:	eb a7                	jmp    801d59 <vprintfmt+0x1cc>
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
				if (altflag && (ch < ' ' || ch > '~'))
  801db2:	83 7d d8 00          	cmpl   $0x0,-0x28(%ebp)
  801db6:	74 1a                	je     801dd2 <vprintfmt+0x245>
  801db8:	8d 50 e0             	lea    -0x20(%eax),%edx
  801dbb:	83 fa 5e             	cmp    $0x5e,%edx
  801dbe:	76 12                	jbe    801dd2 <vprintfmt+0x245>
					putch('?', putdat);
  801dc0:	89 7c 24 04          	mov    %edi,0x4(%esp)
  801dc4:	c7 04 24 3f 00 00 00 	movl   $0x3f,(%esp)
  801dcb:	ff 55 e0             	call   *-0x20(%ebp)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
				if (altflag && (ch < ' ' || ch > '~'))
  801dce:	66 90                	xchg   %ax,%ax
  801dd0:	eb 0a                	jmp    801ddc <vprintfmt+0x24f>
					putch('?', putdat);
				else
					putch(ch, putdat);
  801dd2:	89 7c 24 04          	mov    %edi,0x4(%esp)
  801dd6:	89 04 24             	mov    %eax,(%esp)
  801dd9:	ff 55 e0             	call   *-0x20(%ebp)
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
  801ddc:	83 6d e4 01          	subl   $0x1,-0x1c(%ebp)
  801de0:	0f be 03             	movsbl (%ebx),%eax
  801de3:	85 c0                	test   %eax,%eax
  801de5:	74 05                	je     801dec <vprintfmt+0x25f>
  801de7:	83 c3 01             	add    $0x1,%ebx
  801dea:	eb 29                	jmp    801e15 <vprintfmt+0x288>
  801dec:	89 fe                	mov    %edi,%esi
  801dee:	8b 7d e0             	mov    -0x20(%ebp),%edi
  801df1:	8b 5d d0             	mov    -0x30(%ebp),%ebx
				if (altflag && (ch < ' ' || ch > '~'))
					putch('?', putdat);
				else
					putch(ch, putdat);
			for (; width > 0; width--)
  801df4:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
  801df8:	7f 2e                	jg     801e28 <vprintfmt+0x29b>
  801dfa:	8b 5d cc             	mov    -0x34(%ebp),%ebx
  801dfd:	e9 b7 fd ff ff       	jmp    801bb9 <vprintfmt+0x2c>
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
  801e02:	8b 55 e0             	mov    -0x20(%ebp),%edx
  801e05:	83 c2 01             	add    $0x1,%edx
  801e08:	89 7d e0             	mov    %edi,-0x20(%ebp)
  801e0b:	89 f7                	mov    %esi,%edi
  801e0d:	8b 75 d0             	mov    -0x30(%ebp),%esi
  801e10:	89 5d d0             	mov    %ebx,-0x30(%ebp)
  801e13:	89 d3                	mov    %edx,%ebx
  801e15:	85 f6                	test   %esi,%esi
  801e17:	78 99                	js     801db2 <vprintfmt+0x225>
  801e19:	83 ee 01             	sub    $0x1,%esi
  801e1c:	79 94                	jns    801db2 <vprintfmt+0x225>
  801e1e:	89 fe                	mov    %edi,%esi
  801e20:	8b 7d e0             	mov    -0x20(%ebp),%edi
  801e23:	8b 5d d0             	mov    -0x30(%ebp),%ebx
  801e26:	eb cc                	jmp    801df4 <vprintfmt+0x267>
  801e28:	89 5d d8             	mov    %ebx,-0x28(%ebp)
  801e2b:	8b 5d e4             	mov    -0x1c(%ebp),%ebx
				if (altflag && (ch < ' ' || ch > '~'))
					putch('?', putdat);
				else
					putch(ch, putdat);
			for (; width > 0; width--)
				putch(' ', putdat);
  801e2e:	89 74 24 04          	mov    %esi,0x4(%esp)
  801e32:	c7 04 24 20 00 00 00 	movl   $0x20,(%esp)
  801e39:	ff d7                	call   *%edi
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
				if (altflag && (ch < ' ' || ch > '~'))
					putch('?', putdat);
				else
					putch(ch, putdat);
			for (; width > 0; width--)
  801e3b:	83 eb 01             	sub    $0x1,%ebx
  801e3e:	85 db                	test   %ebx,%ebx
  801e40:	7f ec                	jg     801e2e <vprintfmt+0x2a1>
  801e42:	8b 5d d8             	mov    -0x28(%ebp),%ebx
  801e45:	e9 6f fd ff ff       	jmp    801bb9 <vprintfmt+0x2c>
  801e4a:	89 45 cc             	mov    %eax,-0x34(%ebp)
// Same as getuint but signed - can't use getuint
// because of sign extension
static long long
getint(va_list *ap, int lflag)
{
	if (lflag >= 2)
  801e4d:	83 f9 01             	cmp    $0x1,%ecx
  801e50:	7e 16                	jle    801e68 <vprintfmt+0x2db>
		return va_arg(*ap, long long);
  801e52:	8b 45 14             	mov    0x14(%ebp),%eax
  801e55:	8d 50 08             	lea    0x8(%eax),%edx
  801e58:	89 55 14             	mov    %edx,0x14(%ebp)
  801e5b:	8b 10                	mov    (%eax),%edx
  801e5d:	8b 48 04             	mov    0x4(%eax),%ecx
  801e60:	89 55 d8             	mov    %edx,-0x28(%ebp)
  801e63:	89 4d dc             	mov    %ecx,-0x24(%ebp)
  801e66:	eb 32                	jmp    801e9a <vprintfmt+0x30d>
	else if (lflag)
  801e68:	85 c9                	test   %ecx,%ecx
  801e6a:	74 18                	je     801e84 <vprintfmt+0x2f7>
		return va_arg(*ap, long);
  801e6c:	8b 45 14             	mov    0x14(%ebp),%eax
  801e6f:	8d 50 04             	lea    0x4(%eax),%edx
  801e72:	89 55 14             	mov    %edx,0x14(%ebp)
  801e75:	8b 00                	mov    (%eax),%eax
  801e77:	89 45 d8             	mov    %eax,-0x28(%ebp)
  801e7a:	89 c1                	mov    %eax,%ecx
  801e7c:	c1 f9 1f             	sar    $0x1f,%ecx
  801e7f:	89 4d dc             	mov    %ecx,-0x24(%ebp)
  801e82:	eb 16                	jmp    801e9a <vprintfmt+0x30d>
	else
		return va_arg(*ap, int);
  801e84:	8b 45 14             	mov    0x14(%ebp),%eax
  801e87:	8d 50 04             	lea    0x4(%eax),%edx
  801e8a:	89 55 14             	mov    %edx,0x14(%ebp)
  801e8d:	8b 00                	mov    (%eax),%eax
  801e8f:	89 45 d8             	mov    %eax,-0x28(%ebp)
  801e92:	89 c2                	mov    %eax,%edx
  801e94:	c1 fa 1f             	sar    $0x1f,%edx
  801e97:	89 55 dc             	mov    %edx,-0x24(%ebp)
				putch(' ', putdat);
			break;

		// (signed) decimal
		case 'd':
			num = getint(&ap, lflag);
  801e9a:	8b 4d d8             	mov    -0x28(%ebp),%ecx
  801e9d:	8b 5d dc             	mov    -0x24(%ebp),%ebx
  801ea0:	b8 0a 00 00 00       	mov    $0xa,%eax
			if ((long long) num < 0) {
  801ea5:	83 7d dc 00          	cmpl   $0x0,-0x24(%ebp)
  801ea9:	0f 89 9b 00 00 00    	jns    801f4a <vprintfmt+0x3bd>
				putch('-', putdat);
  801eaf:	89 74 24 04          	mov    %esi,0x4(%esp)
  801eb3:	c7 04 24 2d 00 00 00 	movl   $0x2d,(%esp)
  801eba:	ff d7                	call   *%edi
				num = -(long long) num;
  801ebc:	8b 4d d8             	mov    -0x28(%ebp),%ecx
  801ebf:	8b 5d dc             	mov    -0x24(%ebp),%ebx
  801ec2:	f7 d9                	neg    %ecx
  801ec4:	83 d3 00             	adc    $0x0,%ebx
  801ec7:	f7 db                	neg    %ebx
  801ec9:	b8 0a 00 00 00       	mov    $0xa,%eax
  801ece:	eb 7a                	jmp    801f4a <vprintfmt+0x3bd>
  801ed0:	89 45 cc             	mov    %eax,-0x34(%ebp)
			base = 10;
			goto number;

		// unsigned decimal
		case 'u':
			num = getuint(&ap, lflag);
  801ed3:	89 ca                	mov    %ecx,%edx
  801ed5:	8d 45 14             	lea    0x14(%ebp),%eax
  801ed8:	e8 59 fc ff ff       	call   801b36 <getuint>
  801edd:	89 c1                	mov    %eax,%ecx
  801edf:	89 d3                	mov    %edx,%ebx
  801ee1:	b8 0a 00 00 00       	mov    $0xa,%eax
			base = 10;
			goto number;
  801ee6:	eb 62                	jmp    801f4a <vprintfmt+0x3bd>
  801ee8:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// (unsigned) octal
		case 'o':
			num = getuint(&ap, lflag);
  801eeb:	89 ca                	mov    %ecx,%edx
  801eed:	8d 45 14             	lea    0x14(%ebp),%eax
  801ef0:	e8 41 fc ff ff       	call   801b36 <getuint>
  801ef5:	89 c1                	mov    %eax,%ecx
  801ef7:	89 d3                	mov    %edx,%ebx
  801ef9:	b8 08 00 00 00       	mov    $0x8,%eax
			base = 8;
			goto number;
  801efe:	eb 4a                	jmp    801f4a <vprintfmt+0x3bd>
  801f00:	89 45 cc             	mov    %eax,-0x34(%ebp)
			break;
			**/

		// pointer
		case 'p':
			putch('0', putdat);
  801f03:	89 74 24 04          	mov    %esi,0x4(%esp)
  801f07:	c7 04 24 30 00 00 00 	movl   $0x30,(%esp)
  801f0e:	ff d7                	call   *%edi
			putch('x', putdat);
  801f10:	89 74 24 04          	mov    %esi,0x4(%esp)
  801f14:	c7 04 24 78 00 00 00 	movl   $0x78,(%esp)
  801f1b:	ff d7                	call   *%edi
			num = (unsigned long long)
  801f1d:	8b 45 14             	mov    0x14(%ebp),%eax
  801f20:	8d 50 04             	lea    0x4(%eax),%edx
  801f23:	89 55 14             	mov    %edx,0x14(%ebp)
  801f26:	8b 08                	mov    (%eax),%ecx
  801f28:	bb 00 00 00 00       	mov    $0x0,%ebx
  801f2d:	b8 10 00 00 00       	mov    $0x10,%eax
				(uintptr_t) va_arg(ap, void *);
			base = 16;
			goto number;
  801f32:	eb 16                	jmp    801f4a <vprintfmt+0x3bd>
  801f34:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// (unsigned) hexadecimal
		case 'x':
			num = getuint(&ap, lflag);
  801f37:	89 ca                	mov    %ecx,%edx
  801f39:	8d 45 14             	lea    0x14(%ebp),%eax
  801f3c:	e8 f5 fb ff ff       	call   801b36 <getuint>
  801f41:	89 c1                	mov    %eax,%ecx
  801f43:	89 d3                	mov    %edx,%ebx
  801f45:	b8 10 00 00 00       	mov    $0x10,%eax
			base = 16;
		number:
			printnum(putch, putdat, num, base, width, padc);
  801f4a:	0f be 55 d4          	movsbl -0x2c(%ebp),%edx
  801f4e:	89 54 24 10          	mov    %edx,0x10(%esp)
  801f52:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  801f55:	89 54 24 0c          	mov    %edx,0xc(%esp)
  801f59:	89 44 24 08          	mov    %eax,0x8(%esp)
  801f5d:	89 0c 24             	mov    %ecx,(%esp)
  801f60:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  801f64:	89 f2                	mov    %esi,%edx
  801f66:	89 f8                	mov    %edi,%eax
  801f68:	e8 d3 fa ff ff       	call   801a40 <printnum>
  801f6d:	8b 5d cc             	mov    -0x34(%ebp),%ebx
			break;
  801f70:	e9 44 fc ff ff       	jmp    801bb9 <vprintfmt+0x2c>
  801f75:	89 45 cc             	mov    %eax,-0x34(%ebp)
  801f78:	8b 55 e0             	mov    -0x20(%ebp),%edx

		// escaped '%' character
		case '%':
			putch(ch, putdat);
  801f7b:	89 74 24 04          	mov    %esi,0x4(%esp)
  801f7f:	89 14 24             	mov    %edx,(%esp)
  801f82:	ff d7                	call   *%edi
  801f84:	8b 5d cc             	mov    -0x34(%ebp),%ebx
			break;
  801f87:	e9 2d fc ff ff       	jmp    801bb9 <vprintfmt+0x2c>
			
		// unrecognized escape sequence - just print it literally
		default:
			putch('%', putdat);
  801f8c:	89 74 24 04          	mov    %esi,0x4(%esp)
  801f90:	c7 04 24 25 00 00 00 	movl   $0x25,(%esp)
  801f97:	ff d7                	call   *%edi
			for (fmt--; fmt[-1] != '%'; fmt--)
  801f99:	8d 43 ff             	lea    -0x1(%ebx),%eax
  801f9c:	80 38 25             	cmpb   $0x25,(%eax)
  801f9f:	0f 84 14 fc ff ff    	je     801bb9 <vprintfmt+0x2c>
  801fa5:	89 c3                	mov    %eax,%ebx
  801fa7:	eb f0                	jmp    801f99 <vprintfmt+0x40c>
				/* do nothing */;
			break;
		}
	}
}
  801fa9:	83 c4 5c             	add    $0x5c,%esp
  801fac:	5b                   	pop    %ebx
  801fad:	5e                   	pop    %esi
  801fae:	5f                   	pop    %edi
  801faf:	5d                   	pop    %ebp
  801fb0:	c3                   	ret    

00801fb1 <vsnprintf>:
		*b->buf++ = ch;
}

int
vsnprintf(char *buf, int n, const char *fmt, va_list ap)
{
  801fb1:	55                   	push   %ebp
  801fb2:	89 e5                	mov    %esp,%ebp
  801fb4:	83 ec 28             	sub    $0x28,%esp
  801fb7:	8b 45 08             	mov    0x8(%ebp),%eax
  801fba:	8b 55 0c             	mov    0xc(%ebp),%edx
	struct sprintbuf b = {buf, buf+n-1, 0};

	if (buf == NULL || n < 1)
  801fbd:	85 c0                	test   %eax,%eax
  801fbf:	74 04                	je     801fc5 <vsnprintf+0x14>
  801fc1:	85 d2                	test   %edx,%edx
  801fc3:	7f 07                	jg     801fcc <vsnprintf+0x1b>
  801fc5:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
  801fca:	eb 3b                	jmp    802007 <vsnprintf+0x56>
}

int
vsnprintf(char *buf, int n, const char *fmt, va_list ap)
{
	struct sprintbuf b = {buf, buf+n-1, 0};
  801fcc:	89 45 ec             	mov    %eax,-0x14(%ebp)
  801fcf:	8d 44 10 ff          	lea    -0x1(%eax,%edx,1),%eax
  801fd3:	89 45 f0             	mov    %eax,-0x10(%ebp)
  801fd6:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)

	if (buf == NULL || n < 1)
		return -E_INVAL;

	// print the string to the buffer
	vprintfmt((void*)sprintputch, &b, fmt, ap);
  801fdd:	8b 45 14             	mov    0x14(%ebp),%eax
  801fe0:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801fe4:	8b 45 10             	mov    0x10(%ebp),%eax
  801fe7:	89 44 24 08          	mov    %eax,0x8(%esp)
  801feb:	8d 45 ec             	lea    -0x14(%ebp),%eax
  801fee:	89 44 24 04          	mov    %eax,0x4(%esp)
  801ff2:	c7 04 24 70 1b 80 00 	movl   $0x801b70,(%esp)
  801ff9:	e8 8f fb ff ff       	call   801b8d <vprintfmt>

	// null terminate the buffer
	*b.buf = '\0';
  801ffe:	8b 45 ec             	mov    -0x14(%ebp),%eax
  802001:	c6 00 00             	movb   $0x0,(%eax)

	return b.cnt;
  802004:	8b 45 f4             	mov    -0xc(%ebp),%eax
}
  802007:	c9                   	leave  
  802008:	c3                   	ret    

00802009 <snprintf>:

int
snprintf(char *buf, int n, const char *fmt, ...)
{
  802009:	55                   	push   %ebp
  80200a:	89 e5                	mov    %esp,%ebp
  80200c:	83 ec 18             	sub    $0x18,%esp

	return b.cnt;
}

int
snprintf(char *buf, int n, const char *fmt, ...)
  80200f:	8d 45 14             	lea    0x14(%ebp),%eax
{
	va_list ap;
	int rc;

	va_start(ap, fmt);
	rc = vsnprintf(buf, n, fmt, ap);
  802012:	89 44 24 0c          	mov    %eax,0xc(%esp)
  802016:	8b 45 10             	mov    0x10(%ebp),%eax
  802019:	89 44 24 08          	mov    %eax,0x8(%esp)
  80201d:	8b 45 0c             	mov    0xc(%ebp),%eax
  802020:	89 44 24 04          	mov    %eax,0x4(%esp)
  802024:	8b 45 08             	mov    0x8(%ebp),%eax
  802027:	89 04 24             	mov    %eax,(%esp)
  80202a:	e8 82 ff ff ff       	call   801fb1 <vsnprintf>
	va_end(ap);

	return rc;
}
  80202f:	c9                   	leave  
  802030:	c3                   	ret    

00802031 <printfmt>:
	}
}

void
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...)
{
  802031:	55                   	push   %ebp
  802032:	89 e5                	mov    %esp,%ebp
  802034:	83 ec 18             	sub    $0x18,%esp
		}
	}
}

void
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...)
  802037:	8d 45 14             	lea    0x14(%ebp),%eax
{
	va_list ap;

	va_start(ap, fmt);
	vprintfmt(putch, putdat, fmt, ap);
  80203a:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80203e:	8b 45 10             	mov    0x10(%ebp),%eax
  802041:	89 44 24 08          	mov    %eax,0x8(%esp)
  802045:	8b 45 0c             	mov    0xc(%ebp),%eax
  802048:	89 44 24 04          	mov    %eax,0x4(%esp)
  80204c:	8b 45 08             	mov    0x8(%ebp),%eax
  80204f:	89 04 24             	mov    %eax,(%esp)
  802052:	e8 36 fb ff ff       	call   801b8d <vprintfmt>
	va_end(ap);
}
  802057:	c9                   	leave  
  802058:	c3                   	ret    
  802059:	00 00                	add    %al,(%eax)
  80205b:	00 00                	add    %al,(%eax)
  80205d:	00 00                	add    %al,(%eax)
	...

00802060 <strlen>:
// Primespipe runs 3x faster this way.
#define ASM 1

int
strlen(const char *s)
{
  802060:	55                   	push   %ebp
  802061:	89 e5                	mov    %esp,%ebp
  802063:	8b 55 08             	mov    0x8(%ebp),%edx
	int n;

	for (n = 0; *s != '\0'; s++)
  802066:	b8 00 00 00 00       	mov    $0x0,%eax
  80206b:	80 3a 00             	cmpb   $0x0,(%edx)
  80206e:	74 09                	je     802079 <strlen+0x19>
		n++;
  802070:	83 c0 01             	add    $0x1,%eax
int
strlen(const char *s)
{
	int n;

	for (n = 0; *s != '\0'; s++)
  802073:	80 3c 02 00          	cmpb   $0x0,(%edx,%eax,1)
  802077:	75 f7                	jne    802070 <strlen+0x10>
		n++;
	return n;
}
  802079:	5d                   	pop    %ebp
  80207a:	c3                   	ret    

0080207b <strnlen>:

int
strnlen(const char *s, size_t size)
{
  80207b:	55                   	push   %ebp
  80207c:	89 e5                	mov    %esp,%ebp
  80207e:	53                   	push   %ebx
  80207f:	8b 5d 08             	mov    0x8(%ebp),%ebx
  802082:	8b 4d 0c             	mov    0xc(%ebp),%ecx
	int n;

	for (n = 0; size > 0 && *s != '\0'; s++, size--)
  802085:	85 c9                	test   %ecx,%ecx
  802087:	74 19                	je     8020a2 <strnlen+0x27>
  802089:	80 3b 00             	cmpb   $0x0,(%ebx)
  80208c:	74 14                	je     8020a2 <strnlen+0x27>
  80208e:	b8 00 00 00 00       	mov    $0x0,%eax
		n++;
  802093:	83 c0 01             	add    $0x1,%eax
int
strnlen(const char *s, size_t size)
{
	int n;

	for (n = 0; size > 0 && *s != '\0'; s++, size--)
  802096:	39 c8                	cmp    %ecx,%eax
  802098:	74 0d                	je     8020a7 <strnlen+0x2c>
  80209a:	80 3c 03 00          	cmpb   $0x0,(%ebx,%eax,1)
  80209e:	75 f3                	jne    802093 <strnlen+0x18>
  8020a0:	eb 05                	jmp    8020a7 <strnlen+0x2c>
  8020a2:	b8 00 00 00 00       	mov    $0x0,%eax
		n++;
	return n;
}
  8020a7:	5b                   	pop    %ebx
  8020a8:	5d                   	pop    %ebp
  8020a9:	c3                   	ret    

008020aa <strcpy>:

char *
strcpy(char *dst, const char *src)
{
  8020aa:	55                   	push   %ebp
  8020ab:	89 e5                	mov    %esp,%ebp
  8020ad:	53                   	push   %ebx
  8020ae:	8b 45 08             	mov    0x8(%ebp),%eax
  8020b1:	8b 5d 0c             	mov    0xc(%ebp),%ebx
  8020b4:	ba 00 00 00 00       	mov    $0x0,%edx
	char *ret;

	ret = dst;
	while ((*dst++ = *src++) != '\0')
  8020b9:	0f b6 0c 13          	movzbl (%ebx,%edx,1),%ecx
  8020bd:	88 0c 10             	mov    %cl,(%eax,%edx,1)
  8020c0:	83 c2 01             	add    $0x1,%edx
  8020c3:	84 c9                	test   %cl,%cl
  8020c5:	75 f2                	jne    8020b9 <strcpy+0xf>
		/* do nothing */;
	return ret;
}
  8020c7:	5b                   	pop    %ebx
  8020c8:	5d                   	pop    %ebp
  8020c9:	c3                   	ret    

008020ca <strncpy>:

char *
strncpy(char *dst, const char *src, size_t size) {
  8020ca:	55                   	push   %ebp
  8020cb:	89 e5                	mov    %esp,%ebp
  8020cd:	56                   	push   %esi
  8020ce:	53                   	push   %ebx
  8020cf:	8b 45 08             	mov    0x8(%ebp),%eax
  8020d2:	8b 55 0c             	mov    0xc(%ebp),%edx
  8020d5:	8b 75 10             	mov    0x10(%ebp),%esi
	size_t i;
	char *ret;

	ret = dst;
	for (i = 0; i < size; i++) {
  8020d8:	85 f6                	test   %esi,%esi
  8020da:	74 18                	je     8020f4 <strncpy+0x2a>
  8020dc:	b9 00 00 00 00       	mov    $0x0,%ecx
		*dst++ = *src;
  8020e1:	0f b6 1a             	movzbl (%edx),%ebx
  8020e4:	88 1c 08             	mov    %bl,(%eax,%ecx,1)
		// If strlen(src) < size, null-pad 'dst' out to 'size' chars
		if (*src != '\0')
			src++;
  8020e7:	80 3a 01             	cmpb   $0x1,(%edx)
  8020ea:	83 da ff             	sbb    $0xffffffff,%edx
strncpy(char *dst, const char *src, size_t size) {
	size_t i;
	char *ret;

	ret = dst;
	for (i = 0; i < size; i++) {
  8020ed:	83 c1 01             	add    $0x1,%ecx
  8020f0:	39 ce                	cmp    %ecx,%esi
  8020f2:	77 ed                	ja     8020e1 <strncpy+0x17>
		// If strlen(src) < size, null-pad 'dst' out to 'size' chars
		if (*src != '\0')
			src++;
	}
	return ret;
}
  8020f4:	5b                   	pop    %ebx
  8020f5:	5e                   	pop    %esi
  8020f6:	5d                   	pop    %ebp
  8020f7:	c3                   	ret    

008020f8 <strlcpy>:

size_t
strlcpy(char *dst, const char *src, size_t size)
{
  8020f8:	55                   	push   %ebp
  8020f9:	89 e5                	mov    %esp,%ebp
  8020fb:	56                   	push   %esi
  8020fc:	53                   	push   %ebx
  8020fd:	8b 75 08             	mov    0x8(%ebp),%esi
  802100:	8b 55 0c             	mov    0xc(%ebp),%edx
  802103:	8b 4d 10             	mov    0x10(%ebp),%ecx
	char *dst_in;

	dst_in = dst;
	if (size > 0) {
  802106:	89 f0                	mov    %esi,%eax
  802108:	85 c9                	test   %ecx,%ecx
  80210a:	74 27                	je     802133 <strlcpy+0x3b>
		while (--size > 0 && *src != '\0')
  80210c:	83 e9 01             	sub    $0x1,%ecx
  80210f:	74 1d                	je     80212e <strlcpy+0x36>
  802111:	0f b6 1a             	movzbl (%edx),%ebx
  802114:	84 db                	test   %bl,%bl
  802116:	74 16                	je     80212e <strlcpy+0x36>
			*dst++ = *src++;
  802118:	88 18                	mov    %bl,(%eax)
  80211a:	83 c0 01             	add    $0x1,%eax
{
	char *dst_in;

	dst_in = dst;
	if (size > 0) {
		while (--size > 0 && *src != '\0')
  80211d:	83 e9 01             	sub    $0x1,%ecx
  802120:	74 0e                	je     802130 <strlcpy+0x38>
			*dst++ = *src++;
  802122:	83 c2 01             	add    $0x1,%edx
{
	char *dst_in;

	dst_in = dst;
	if (size > 0) {
		while (--size > 0 && *src != '\0')
  802125:	0f b6 1a             	movzbl (%edx),%ebx
  802128:	84 db                	test   %bl,%bl
  80212a:	75 ec                	jne    802118 <strlcpy+0x20>
  80212c:	eb 02                	jmp    802130 <strlcpy+0x38>
  80212e:	89 f0                	mov    %esi,%eax
			*dst++ = *src++;
		*dst = '\0';
  802130:	c6 00 00             	movb   $0x0,(%eax)
  802133:	29 f0                	sub    %esi,%eax
	}
	return dst - dst_in;
}
  802135:	5b                   	pop    %ebx
  802136:	5e                   	pop    %esi
  802137:	5d                   	pop    %ebp
  802138:	c3                   	ret    

00802139 <strcmp>:

int
strcmp(const char *p, const char *q)
{
  802139:	55                   	push   %ebp
  80213a:	89 e5                	mov    %esp,%ebp
  80213c:	8b 4d 08             	mov    0x8(%ebp),%ecx
  80213f:	8b 55 0c             	mov    0xc(%ebp),%edx
	while (*p && *p == *q)
  802142:	0f b6 01             	movzbl (%ecx),%eax
  802145:	84 c0                	test   %al,%al
  802147:	74 15                	je     80215e <strcmp+0x25>
  802149:	3a 02                	cmp    (%edx),%al
  80214b:	75 11                	jne    80215e <strcmp+0x25>
		p++, q++;
  80214d:	83 c1 01             	add    $0x1,%ecx
  802150:	83 c2 01             	add    $0x1,%edx
}

int
strcmp(const char *p, const char *q)
{
	while (*p && *p == *q)
  802153:	0f b6 01             	movzbl (%ecx),%eax
  802156:	84 c0                	test   %al,%al
  802158:	74 04                	je     80215e <strcmp+0x25>
  80215a:	3a 02                	cmp    (%edx),%al
  80215c:	74 ef                	je     80214d <strcmp+0x14>
  80215e:	0f b6 c0             	movzbl %al,%eax
  802161:	0f b6 12             	movzbl (%edx),%edx
  802164:	29 d0                	sub    %edx,%eax
		p++, q++;
	return (int) ((unsigned char) *p - (unsigned char) *q);
}
  802166:	5d                   	pop    %ebp
  802167:	c3                   	ret    

00802168 <strncmp>:

int
strncmp(const char *p, const char *q, size_t n)
{
  802168:	55                   	push   %ebp
  802169:	89 e5                	mov    %esp,%ebp
  80216b:	53                   	push   %ebx
  80216c:	8b 55 08             	mov    0x8(%ebp),%edx
  80216f:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  802172:	8b 45 10             	mov    0x10(%ebp),%eax
	while (n > 0 && *p && *p == *q)
  802175:	85 c0                	test   %eax,%eax
  802177:	74 23                	je     80219c <strncmp+0x34>
  802179:	0f b6 1a             	movzbl (%edx),%ebx
  80217c:	84 db                	test   %bl,%bl
  80217e:	74 24                	je     8021a4 <strncmp+0x3c>
  802180:	3a 19                	cmp    (%ecx),%bl
  802182:	75 20                	jne    8021a4 <strncmp+0x3c>
  802184:	83 e8 01             	sub    $0x1,%eax
  802187:	74 13                	je     80219c <strncmp+0x34>
		n--, p++, q++;
  802189:	83 c2 01             	add    $0x1,%edx
  80218c:	83 c1 01             	add    $0x1,%ecx
}

int
strncmp(const char *p, const char *q, size_t n)
{
	while (n > 0 && *p && *p == *q)
  80218f:	0f b6 1a             	movzbl (%edx),%ebx
  802192:	84 db                	test   %bl,%bl
  802194:	74 0e                	je     8021a4 <strncmp+0x3c>
  802196:	3a 19                	cmp    (%ecx),%bl
  802198:	74 ea                	je     802184 <strncmp+0x1c>
  80219a:	eb 08                	jmp    8021a4 <strncmp+0x3c>
  80219c:	b8 00 00 00 00       	mov    $0x0,%eax
		n--, p++, q++;
	if (n == 0)
		return 0;
	else
		return (int) ((unsigned char) *p - (unsigned char) *q);
}
  8021a1:	5b                   	pop    %ebx
  8021a2:	5d                   	pop    %ebp
  8021a3:	c3                   	ret    
	while (n > 0 && *p && *p == *q)
		n--, p++, q++;
	if (n == 0)
		return 0;
	else
		return (int) ((unsigned char) *p - (unsigned char) *q);
  8021a4:	0f b6 02             	movzbl (%edx),%eax
  8021a7:	0f b6 11             	movzbl (%ecx),%edx
  8021aa:	29 d0                	sub    %edx,%eax
  8021ac:	eb f3                	jmp    8021a1 <strncmp+0x39>

008021ae <strchr>:

// Return a pointer to the first occurrence of 'c' in 's',
// or a null pointer if the string has no 'c'.
char *
strchr(const char *s, char c)
{
  8021ae:	55                   	push   %ebp
  8021af:	89 e5                	mov    %esp,%ebp
  8021b1:	8b 45 08             	mov    0x8(%ebp),%eax
  8021b4:	0f b6 4d 0c          	movzbl 0xc(%ebp),%ecx
	for (; *s; s++)
  8021b8:	0f b6 10             	movzbl (%eax),%edx
  8021bb:	84 d2                	test   %dl,%dl
  8021bd:	74 15                	je     8021d4 <strchr+0x26>
		if (*s == c)
  8021bf:	38 ca                	cmp    %cl,%dl
  8021c1:	75 07                	jne    8021ca <strchr+0x1c>
  8021c3:	eb 14                	jmp    8021d9 <strchr+0x2b>
  8021c5:	38 ca                	cmp    %cl,%dl
  8021c7:	90                   	nop
  8021c8:	74 0f                	je     8021d9 <strchr+0x2b>
// Return a pointer to the first occurrence of 'c' in 's',
// or a null pointer if the string has no 'c'.
char *
strchr(const char *s, char c)
{
	for (; *s; s++)
  8021ca:	83 c0 01             	add    $0x1,%eax
  8021cd:	0f b6 10             	movzbl (%eax),%edx
  8021d0:	84 d2                	test   %dl,%dl
  8021d2:	75 f1                	jne    8021c5 <strchr+0x17>
  8021d4:	b8 00 00 00 00       	mov    $0x0,%eax
		if (*s == c)
			return (char *) s;
	return 0;
}
  8021d9:	5d                   	pop    %ebp
  8021da:	c3                   	ret    

008021db <strfind>:

// Return a pointer to the first occurrence of 'c' in 's',
// or a pointer to the string-ending null character if the string has no 'c'.
char *
strfind(const char *s, char c)
{
  8021db:	55                   	push   %ebp
  8021dc:	89 e5                	mov    %esp,%ebp
  8021de:	8b 45 08             	mov    0x8(%ebp),%eax
  8021e1:	0f b6 4d 0c          	movzbl 0xc(%ebp),%ecx
	for (; *s; s++)
  8021e5:	0f b6 10             	movzbl (%eax),%edx
  8021e8:	84 d2                	test   %dl,%dl
  8021ea:	74 18                	je     802204 <strfind+0x29>
		if (*s == c)
  8021ec:	38 ca                	cmp    %cl,%dl
  8021ee:	75 0a                	jne    8021fa <strfind+0x1f>
  8021f0:	eb 12                	jmp    802204 <strfind+0x29>
  8021f2:	38 ca                	cmp    %cl,%dl
  8021f4:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  8021f8:	74 0a                	je     802204 <strfind+0x29>
// Return a pointer to the first occurrence of 'c' in 's',
// or a pointer to the string-ending null character if the string has no 'c'.
char *
strfind(const char *s, char c)
{
	for (; *s; s++)
  8021fa:	83 c0 01             	add    $0x1,%eax
  8021fd:	0f b6 10             	movzbl (%eax),%edx
  802200:	84 d2                	test   %dl,%dl
  802202:	75 ee                	jne    8021f2 <strfind+0x17>
		if (*s == c)
			break;
	return (char *) s;
}
  802204:	5d                   	pop    %ebp
  802205:	c3                   	ret    

00802206 <memset>:

#if ASM
void *
memset(void *v, int c, size_t n)
{
  802206:	55                   	push   %ebp
  802207:	89 e5                	mov    %esp,%ebp
  802209:	83 ec 0c             	sub    $0xc,%esp
  80220c:	89 1c 24             	mov    %ebx,(%esp)
  80220f:	89 74 24 04          	mov    %esi,0x4(%esp)
  802213:	89 7c 24 08          	mov    %edi,0x8(%esp)
  802217:	8b 7d 08             	mov    0x8(%ebp),%edi
  80221a:	8b 45 0c             	mov    0xc(%ebp),%eax
  80221d:	8b 4d 10             	mov    0x10(%ebp),%ecx
	char *p;

	if (n == 0)
  802220:	85 c9                	test   %ecx,%ecx
  802222:	74 30                	je     802254 <memset+0x4e>
		return v;
	if ((int)v%4 == 0 && n%4 == 0) {
  802224:	f7 c7 03 00 00 00    	test   $0x3,%edi
  80222a:	75 25                	jne    802251 <memset+0x4b>
  80222c:	f6 c1 03             	test   $0x3,%cl
  80222f:	75 20                	jne    802251 <memset+0x4b>
		c &= 0xFF;
  802231:	0f b6 d0             	movzbl %al,%edx
		c = (c<<24)|(c<<16)|(c<<8)|c;
  802234:	89 d3                	mov    %edx,%ebx
  802236:	c1 e3 08             	shl    $0x8,%ebx
  802239:	89 d6                	mov    %edx,%esi
  80223b:	c1 e6 18             	shl    $0x18,%esi
  80223e:	89 d0                	mov    %edx,%eax
  802240:	c1 e0 10             	shl    $0x10,%eax
  802243:	09 f0                	or     %esi,%eax
  802245:	09 d0                	or     %edx,%eax
		asm volatile("cld; rep stosl\n"
  802247:	09 d8                	or     %ebx,%eax
  802249:	c1 e9 02             	shr    $0x2,%ecx
  80224c:	fc                   	cld    
  80224d:	f3 ab                	rep stos %eax,%es:(%edi)
{
	char *p;

	if (n == 0)
		return v;
	if ((int)v%4 == 0 && n%4 == 0) {
  80224f:	eb 03                	jmp    802254 <memset+0x4e>
		c = (c<<24)|(c<<16)|(c<<8)|c;
		asm volatile("cld; rep stosl\n"
			:: "D" (v), "a" (c), "c" (n/4)
			: "cc", "memory");
	} else
		asm volatile("cld; rep stosb\n"
  802251:	fc                   	cld    
  802252:	f3 aa                	rep stos %al,%es:(%edi)
			:: "D" (v), "a" (c), "c" (n)
			: "cc", "memory");
	return v;
}
  802254:	89 f8                	mov    %edi,%eax
  802256:	8b 1c 24             	mov    (%esp),%ebx
  802259:	8b 74 24 04          	mov    0x4(%esp),%esi
  80225d:	8b 7c 24 08          	mov    0x8(%esp),%edi
  802261:	89 ec                	mov    %ebp,%esp
  802263:	5d                   	pop    %ebp
  802264:	c3                   	ret    

00802265 <memmove>:

void *
memmove(void *dst, const void *src, size_t n)
{
  802265:	55                   	push   %ebp
  802266:	89 e5                	mov    %esp,%ebp
  802268:	83 ec 08             	sub    $0x8,%esp
  80226b:	89 34 24             	mov    %esi,(%esp)
  80226e:	89 7c 24 04          	mov    %edi,0x4(%esp)
  802272:	8b 45 08             	mov    0x8(%ebp),%eax
  802275:	8b 4d 10             	mov    0x10(%ebp),%ecx
	const char *s;
	char *d;
	
	s = src;
  802278:	8b 75 0c             	mov    0xc(%ebp),%esi
	d = dst;
  80227b:	89 c7                	mov    %eax,%edi
	if (s < d && s + n > d) {
  80227d:	39 c6                	cmp    %eax,%esi
  80227f:	73 35                	jae    8022b6 <memmove+0x51>
  802281:	8d 14 0e             	lea    (%esi,%ecx,1),%edx
  802284:	39 d0                	cmp    %edx,%eax
  802286:	73 2e                	jae    8022b6 <memmove+0x51>
		s += n;
		d += n;
  802288:	01 cf                	add    %ecx,%edi
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  80228a:	f6 c2 03             	test   $0x3,%dl
  80228d:	75 1b                	jne    8022aa <memmove+0x45>
  80228f:	f7 c7 03 00 00 00    	test   $0x3,%edi
  802295:	75 13                	jne    8022aa <memmove+0x45>
  802297:	f6 c1 03             	test   $0x3,%cl
  80229a:	75 0e                	jne    8022aa <memmove+0x45>
			asm volatile("std; rep movsl\n"
  80229c:	83 ef 04             	sub    $0x4,%edi
  80229f:	8d 72 fc             	lea    -0x4(%edx),%esi
  8022a2:	c1 e9 02             	shr    $0x2,%ecx
  8022a5:	fd                   	std    
  8022a6:	f3 a5                	rep movsl %ds:(%esi),%es:(%edi)
	s = src;
	d = dst;
	if (s < d && s + n > d) {
		s += n;
		d += n;
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  8022a8:	eb 09                	jmp    8022b3 <memmove+0x4e>
			asm volatile("std; rep movsl\n"
				:: "D" (d-4), "S" (s-4), "c" (n/4) : "cc", "memory");
		else
			asm volatile("std; rep movsb\n"
  8022aa:	83 ef 01             	sub    $0x1,%edi
  8022ad:	8d 72 ff             	lea    -0x1(%edx),%esi
  8022b0:	fd                   	std    
  8022b1:	f3 a4                	rep movsb %ds:(%esi),%es:(%edi)
				:: "D" (d-1), "S" (s-1), "c" (n) : "cc", "memory");
		// Some versions of GCC rely on DF being clear
		asm volatile("cld" ::: "cc");
  8022b3:	fc                   	cld    
	const char *s;
	char *d;
	
	s = src;
	d = dst;
	if (s < d && s + n > d) {
  8022b4:	eb 20                	jmp    8022d6 <memmove+0x71>
			asm volatile("std; rep movsb\n"
				:: "D" (d-1), "S" (s-1), "c" (n) : "cc", "memory");
		// Some versions of GCC rely on DF being clear
		asm volatile("cld" ::: "cc");
	} else {
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  8022b6:	f7 c6 03 00 00 00    	test   $0x3,%esi
  8022bc:	75 15                	jne    8022d3 <memmove+0x6e>
  8022be:	f7 c7 03 00 00 00    	test   $0x3,%edi
  8022c4:	75 0d                	jne    8022d3 <memmove+0x6e>
  8022c6:	f6 c1 03             	test   $0x3,%cl
  8022c9:	75 08                	jne    8022d3 <memmove+0x6e>
			asm volatile("cld; rep movsl\n"
  8022cb:	c1 e9 02             	shr    $0x2,%ecx
  8022ce:	fc                   	cld    
  8022cf:	f3 a5                	rep movsl %ds:(%esi),%es:(%edi)
			asm volatile("std; rep movsb\n"
				:: "D" (d-1), "S" (s-1), "c" (n) : "cc", "memory");
		// Some versions of GCC rely on DF being clear
		asm volatile("cld" ::: "cc");
	} else {
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  8022d1:	eb 03                	jmp    8022d6 <memmove+0x71>
			asm volatile("cld; rep movsl\n"
				:: "D" (d), "S" (s), "c" (n/4) : "cc", "memory");
		else
			asm volatile("cld; rep movsb\n"
  8022d3:	fc                   	cld    
  8022d4:	f3 a4                	rep movsb %ds:(%esi),%es:(%edi)
				:: "D" (d), "S" (s), "c" (n) : "cc", "memory");
	}
	return dst;
}
  8022d6:	8b 34 24             	mov    (%esp),%esi
  8022d9:	8b 7c 24 04          	mov    0x4(%esp),%edi
  8022dd:	89 ec                	mov    %ebp,%esp
  8022df:	5d                   	pop    %ebp
  8022e0:	c3                   	ret    

008022e1 <memcpy>:

/* sigh - gcc emits references to this for structure assignments! */
/* it is *not* prototyped in inc/string.h - do not use directly. */
void *
memcpy(void *dst, void *src, size_t n)
{
  8022e1:	55                   	push   %ebp
  8022e2:	89 e5                	mov    %esp,%ebp
  8022e4:	83 ec 0c             	sub    $0xc,%esp
	return memmove(dst, src, n);
  8022e7:	8b 45 10             	mov    0x10(%ebp),%eax
  8022ea:	89 44 24 08          	mov    %eax,0x8(%esp)
  8022ee:	8b 45 0c             	mov    0xc(%ebp),%eax
  8022f1:	89 44 24 04          	mov    %eax,0x4(%esp)
  8022f5:	8b 45 08             	mov    0x8(%ebp),%eax
  8022f8:	89 04 24             	mov    %eax,(%esp)
  8022fb:	e8 65 ff ff ff       	call   802265 <memmove>
}
  802300:	c9                   	leave  
  802301:	c3                   	ret    

00802302 <memcmp>:

int
memcmp(const void *v1, const void *v2, size_t n)
{
  802302:	55                   	push   %ebp
  802303:	89 e5                	mov    %esp,%ebp
  802305:	57                   	push   %edi
  802306:	56                   	push   %esi
  802307:	53                   	push   %ebx
  802308:	8b 75 08             	mov    0x8(%ebp),%esi
  80230b:	8b 7d 0c             	mov    0xc(%ebp),%edi
  80230e:	8b 4d 10             	mov    0x10(%ebp),%ecx
	const uint8_t *s1 = (const uint8_t *) v1;
	const uint8_t *s2 = (const uint8_t *) v2;

	while (n-- > 0) {
  802311:	85 c9                	test   %ecx,%ecx
  802313:	74 36                	je     80234b <memcmp+0x49>
		if (*s1 != *s2)
  802315:	0f b6 06             	movzbl (%esi),%eax
  802318:	0f b6 1f             	movzbl (%edi),%ebx
  80231b:	38 d8                	cmp    %bl,%al
  80231d:	74 20                	je     80233f <memcmp+0x3d>
  80231f:	eb 14                	jmp    802335 <memcmp+0x33>
  802321:	0f b6 44 16 01       	movzbl 0x1(%esi,%edx,1),%eax
  802326:	0f b6 5c 17 01       	movzbl 0x1(%edi,%edx,1),%ebx
  80232b:	83 c2 01             	add    $0x1,%edx
  80232e:	83 e9 01             	sub    $0x1,%ecx
  802331:	38 d8                	cmp    %bl,%al
  802333:	74 12                	je     802347 <memcmp+0x45>
			return (int) *s1 - (int) *s2;
  802335:	0f b6 c0             	movzbl %al,%eax
  802338:	0f b6 db             	movzbl %bl,%ebx
  80233b:	29 d8                	sub    %ebx,%eax
  80233d:	eb 11                	jmp    802350 <memcmp+0x4e>
memcmp(const void *v1, const void *v2, size_t n)
{
	const uint8_t *s1 = (const uint8_t *) v1;
	const uint8_t *s2 = (const uint8_t *) v2;

	while (n-- > 0) {
  80233f:	83 e9 01             	sub    $0x1,%ecx
  802342:	ba 00 00 00 00       	mov    $0x0,%edx
  802347:	85 c9                	test   %ecx,%ecx
  802349:	75 d6                	jne    802321 <memcmp+0x1f>
  80234b:	b8 00 00 00 00       	mov    $0x0,%eax
			return (int) *s1 - (int) *s2;
		s1++, s2++;
	}

	return 0;
}
  802350:	5b                   	pop    %ebx
  802351:	5e                   	pop    %esi
  802352:	5f                   	pop    %edi
  802353:	5d                   	pop    %ebp
  802354:	c3                   	ret    

00802355 <memfind>:

void *
memfind(const void *s, int c, size_t n)
{
  802355:	55                   	push   %ebp
  802356:	89 e5                	mov    %esp,%ebp
  802358:	8b 45 08             	mov    0x8(%ebp),%eax
	const void *ends = (const char *) s + n;
  80235b:	89 c2                	mov    %eax,%edx
  80235d:	03 55 10             	add    0x10(%ebp),%edx
	for (; s < ends; s++)
  802360:	39 d0                	cmp    %edx,%eax
  802362:	73 15                	jae    802379 <memfind+0x24>
		if (*(const unsigned char *) s == (unsigned char) c)
  802364:	0f b6 4d 0c          	movzbl 0xc(%ebp),%ecx
  802368:	38 08                	cmp    %cl,(%eax)
  80236a:	75 06                	jne    802372 <memfind+0x1d>
  80236c:	eb 0b                	jmp    802379 <memfind+0x24>
  80236e:	38 08                	cmp    %cl,(%eax)
  802370:	74 07                	je     802379 <memfind+0x24>

void *
memfind(const void *s, int c, size_t n)
{
	const void *ends = (const char *) s + n;
	for (; s < ends; s++)
  802372:	83 c0 01             	add    $0x1,%eax
  802375:	39 c2                	cmp    %eax,%edx
  802377:	77 f5                	ja     80236e <memfind+0x19>
		if (*(const unsigned char *) s == (unsigned char) c)
			break;
	return (void *) s;
}
  802379:	5d                   	pop    %ebp
  80237a:	c3                   	ret    

0080237b <strtol>:

long
strtol(const char *s, char **endptr, int base)
{
  80237b:	55                   	push   %ebp
  80237c:	89 e5                	mov    %esp,%ebp
  80237e:	57                   	push   %edi
  80237f:	56                   	push   %esi
  802380:	53                   	push   %ebx
  802381:	83 ec 04             	sub    $0x4,%esp
  802384:	8b 55 08             	mov    0x8(%ebp),%edx
  802387:	8b 5d 10             	mov    0x10(%ebp),%ebx
	int neg = 0;
	long val = 0;

	// gobble initial whitespace
	while (*s == ' ' || *s == '\t')
  80238a:	0f b6 02             	movzbl (%edx),%eax
  80238d:	3c 20                	cmp    $0x20,%al
  80238f:	74 04                	je     802395 <strtol+0x1a>
  802391:	3c 09                	cmp    $0x9,%al
  802393:	75 0e                	jne    8023a3 <strtol+0x28>
		s++;
  802395:	83 c2 01             	add    $0x1,%edx
{
	int neg = 0;
	long val = 0;

	// gobble initial whitespace
	while (*s == ' ' || *s == '\t')
  802398:	0f b6 02             	movzbl (%edx),%eax
  80239b:	3c 20                	cmp    $0x20,%al
  80239d:	74 f6                	je     802395 <strtol+0x1a>
  80239f:	3c 09                	cmp    $0x9,%al
  8023a1:	74 f2                	je     802395 <strtol+0x1a>
		s++;

	// plus/minus sign
	if (*s == '+')
  8023a3:	3c 2b                	cmp    $0x2b,%al
  8023a5:	75 0c                	jne    8023b3 <strtol+0x38>
		s++;
  8023a7:	83 c2 01             	add    $0x1,%edx
  8023aa:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  8023b1:	eb 15                	jmp    8023c8 <strtol+0x4d>
	else if (*s == '-')
  8023b3:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  8023ba:	3c 2d                	cmp    $0x2d,%al
  8023bc:	75 0a                	jne    8023c8 <strtol+0x4d>
		s++, neg = 1;
  8023be:	83 c2 01             	add    $0x1,%edx
  8023c1:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)

	// hex or octal base prefix
	if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
  8023c8:	85 db                	test   %ebx,%ebx
  8023ca:	0f 94 c0             	sete   %al
  8023cd:	74 05                	je     8023d4 <strtol+0x59>
  8023cf:	83 fb 10             	cmp    $0x10,%ebx
  8023d2:	75 18                	jne    8023ec <strtol+0x71>
  8023d4:	80 3a 30             	cmpb   $0x30,(%edx)
  8023d7:	75 13                	jne    8023ec <strtol+0x71>
  8023d9:	80 7a 01 78          	cmpb   $0x78,0x1(%edx)
  8023dd:	8d 76 00             	lea    0x0(%esi),%esi
  8023e0:	75 0a                	jne    8023ec <strtol+0x71>
		s += 2, base = 16;
  8023e2:	83 c2 02             	add    $0x2,%edx
  8023e5:	bb 10 00 00 00       	mov    $0x10,%ebx
		s++;
	else if (*s == '-')
		s++, neg = 1;

	// hex or octal base prefix
	if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
  8023ea:	eb 15                	jmp    802401 <strtol+0x86>
		s += 2, base = 16;
	else if (base == 0 && s[0] == '0')
  8023ec:	84 c0                	test   %al,%al
  8023ee:	66 90                	xchg   %ax,%ax
  8023f0:	74 0f                	je     802401 <strtol+0x86>
  8023f2:	bb 0a 00 00 00       	mov    $0xa,%ebx
  8023f7:	80 3a 30             	cmpb   $0x30,(%edx)
  8023fa:	75 05                	jne    802401 <strtol+0x86>
		s++, base = 8;
  8023fc:	83 c2 01             	add    $0x1,%edx
  8023ff:	b3 08                	mov    $0x8,%bl
		s++, neg = 1;

	// hex or octal base prefix
	if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
		s += 2, base = 16;
	else if (base == 0 && s[0] == '0')
  802401:	b8 00 00 00 00       	mov    $0x0,%eax
  802406:	89 de                	mov    %ebx,%esi

	// digits
	while (1) {
		int dig;

		if (*s >= '0' && *s <= '9')
  802408:	0f b6 0a             	movzbl (%edx),%ecx
  80240b:	89 cf                	mov    %ecx,%edi
  80240d:	8d 59 d0             	lea    -0x30(%ecx),%ebx
  802410:	80 fb 09             	cmp    $0x9,%bl
  802413:	77 08                	ja     80241d <strtol+0xa2>
			dig = *s - '0';
  802415:	0f be c9             	movsbl %cl,%ecx
  802418:	83 e9 30             	sub    $0x30,%ecx
  80241b:	eb 1e                	jmp    80243b <strtol+0xc0>
		else if (*s >= 'a' && *s <= 'z')
  80241d:	8d 5f 9f             	lea    -0x61(%edi),%ebx
  802420:	80 fb 19             	cmp    $0x19,%bl
  802423:	77 08                	ja     80242d <strtol+0xb2>
			dig = *s - 'a' + 10;
  802425:	0f be c9             	movsbl %cl,%ecx
  802428:	83 e9 57             	sub    $0x57,%ecx
  80242b:	eb 0e                	jmp    80243b <strtol+0xc0>
		else if (*s >= 'A' && *s <= 'Z')
  80242d:	8d 5f bf             	lea    -0x41(%edi),%ebx
  802430:	80 fb 19             	cmp    $0x19,%bl
  802433:	77 15                	ja     80244a <strtol+0xcf>
			dig = *s - 'A' + 10;
  802435:	0f be c9             	movsbl %cl,%ecx
  802438:	83 e9 37             	sub    $0x37,%ecx
		else
			break;
		if (dig >= base)
  80243b:	39 f1                	cmp    %esi,%ecx
  80243d:	7d 0b                	jge    80244a <strtol+0xcf>
			break;
		s++, val = (val * base) + dig;
  80243f:	83 c2 01             	add    $0x1,%edx
  802442:	0f af c6             	imul   %esi,%eax
  802445:	8d 04 01             	lea    (%ecx,%eax,1),%eax
		// we don't properly detect overflow!
	}
  802448:	eb be                	jmp    802408 <strtol+0x8d>
  80244a:	89 c1                	mov    %eax,%ecx

	if (endptr)
  80244c:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
  802450:	74 05                	je     802457 <strtol+0xdc>
		*endptr = (char *) s;
  802452:	8b 5d 0c             	mov    0xc(%ebp),%ebx
  802455:	89 13                	mov    %edx,(%ebx)
	return (neg ? -val : val);
  802457:	89 ca                	mov    %ecx,%edx
  802459:	f7 da                	neg    %edx
  80245b:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
  80245f:	0f 45 c2             	cmovne %edx,%eax
}
  802462:	83 c4 04             	add    $0x4,%esp
  802465:	5b                   	pop    %ebx
  802466:	5e                   	pop    %esi
  802467:	5f                   	pop    %edi
  802468:	5d                   	pop    %ebp
  802469:	c3                   	ret    
  80246a:	00 00                	add    %al,(%eax)
  80246c:	00 00                	add    %al,(%eax)
	...

00802470 <ipc_send>:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
  802470:	55                   	push   %ebp
  802471:	89 e5                	mov    %esp,%ebp
  802473:	57                   	push   %edi
  802474:	56                   	push   %esi
  802475:	53                   	push   %ebx
  802476:	83 ec 2c             	sub    $0x2c,%esp
  802479:	8b 75 08             	mov    0x8(%ebp),%esi
  80247c:	8b 7d 0c             	mov    0xc(%ebp),%edi
  80247f:	8b 5d 10             	mov    0x10(%ebp),%ebx
  int r   = 0;
  while (1) {
    if ((r=sys_ipc_try_send(to_env, val, (pg==NULL?(void *)UTOP:pg), perm)) == -E_IPC_NOT_RECV)
  802482:	85 db                	test   %ebx,%ebx
  802484:	b8 00 00 c0 ee       	mov    $0xeec00000,%eax
  802489:	0f 45 c3             	cmovne %ebx,%eax
  80248c:	8b 55 14             	mov    0x14(%ebp),%edx
  80248f:	89 54 24 0c          	mov    %edx,0xc(%esp)
  802493:	89 44 24 08          	mov    %eax,0x8(%esp)
  802497:	89 7c 24 04          	mov    %edi,0x4(%esp)
  80249b:	89 34 24             	mov    %esi,(%esp)
  80249e:	e8 79 dd ff ff       	call   80021c <sys_ipc_try_send>
  8024a3:	83 f8 f9             	cmp    $0xfffffff9,%eax
  8024a6:	75 0a                	jne    8024b2 <ipc_send+0x42>
      sys_yield();
  8024a8:	e8 04 e0 ff ff       	call   8004b1 <sys_yield>
    else if (r < 0)
      panic("ipc_send to [%x] failed. Error: %x\n", to_env, r);
    else
      return;
  }
  8024ad:	8d 76 00             	lea    0x0(%esi),%esi
  8024b0:	eb d0                	jmp    802482 <ipc_send+0x12>
{
  int r   = 0;
  while (1) {
    if ((r=sys_ipc_try_send(to_env, val, (pg==NULL?(void *)UTOP:pg), perm)) == -E_IPC_NOT_RECV)
      sys_yield();
    else if (r < 0)
  8024b2:	85 c0                	test   %eax,%eax
  8024b4:	79 24                	jns    8024da <ipc_send+0x6a>
      panic("ipc_send to [%x] failed. Error: %x\n", to_env, r);
  8024b6:	89 44 24 10          	mov    %eax,0x10(%esp)
  8024ba:	89 74 24 0c          	mov    %esi,0xc(%esp)
  8024be:	c7 44 24 08 8c 2c 80 	movl   $0x802c8c,0x8(%esp)
  8024c5:	00 
  8024c6:	c7 44 24 04 36 00 00 	movl   $0x36,0x4(%esp)
  8024cd:	00 
  8024ce:	c7 04 24 b0 2c 80 00 	movl   $0x802cb0,(%esp)
  8024d5:	e8 3a f4 ff ff       	call   801914 <_panic>
    else
      return;
  }
}
  8024da:	83 c4 2c             	add    $0x2c,%esp
  8024dd:	5b                   	pop    %ebx
  8024de:	5e                   	pop    %esi
  8024df:	5f                   	pop    %edi
  8024e0:	5d                   	pop    %ebp
  8024e1:	c3                   	ret    

008024e2 <ipc_recv>:
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value, since that's
//   a perfectly valid place to map a page.)
int32_t
ipc_recv(envid_t *from_env_store, void *pg, int *perm_store)
{
  8024e2:	55                   	push   %ebp
  8024e3:	89 e5                	mov    %esp,%ebp
  8024e5:	56                   	push   %esi
  8024e6:	53                   	push   %ebx
  8024e7:	83 ec 10             	sub    $0x10,%esp
  8024ea:	8b 5d 08             	mov    0x8(%ebp),%ebx
  8024ed:	8b 45 0c             	mov    0xc(%ebp),%eax
  8024f0:	8b 75 10             	mov    0x10(%ebp),%esi
  int r;
  if ((r=sys_ipc_recv((pg==NULL?(void *)UTOP:pg)))<0)
  8024f3:	85 c0                	test   %eax,%eax
  8024f5:	ba 00 00 c0 ee       	mov    $0xeec00000,%edx
  8024fa:	0f 44 c2             	cmove  %edx,%eax
  8024fd:	89 04 24             	mov    %eax,(%esp)
  802500:	e8 ba dc ff ff       	call   8001bf <sys_ipc_recv>
  802505:	85 c0                	test   %eax,%eax
  802507:	78 24                	js     80252d <ipc_recv+0x4b>
    return r;

  if (from_env_store)
  802509:	85 db                	test   %ebx,%ebx
  80250b:	74 0a                	je     802517 <ipc_recv+0x35>
    *from_env_store = env->env_ipc_from;
  80250d:	a1 74 60 80 00       	mov    0x806074,%eax
  802512:	8b 40 74             	mov    0x74(%eax),%eax
  802515:	89 03                	mov    %eax,(%ebx)

  if (perm_store)
  802517:	85 f6                	test   %esi,%esi
  802519:	74 0a                	je     802525 <ipc_recv+0x43>
    *perm_store     = env->env_ipc_perm;
  80251b:	a1 74 60 80 00       	mov    0x806074,%eax
  802520:	8b 40 78             	mov    0x78(%eax),%eax
  802523:	89 06                	mov    %eax,(%esi)

  return env->env_ipc_value;
  802525:	a1 74 60 80 00       	mov    0x806074,%eax
  80252a:	8b 40 70             	mov    0x70(%eax),%eax
}
  80252d:	83 c4 10             	add    $0x10,%esp
  802530:	5b                   	pop    %ebx
  802531:	5e                   	pop    %esi
  802532:	5d                   	pop    %ebp
  802533:	c3                   	ret    

00802534 <pageref>:
#include <inc/lib.h>

int
pageref(void *v)
{
  802534:	55                   	push   %ebp
  802535:	89 e5                	mov    %esp,%ebp
	pte_t pte;

	if (!(vpd[PDX(v)] & PTE_P))
  802537:	8b 45 08             	mov    0x8(%ebp),%eax
  80253a:	89 c2                	mov    %eax,%edx
  80253c:	c1 ea 16             	shr    $0x16,%edx
  80253f:	8b 14 95 00 d0 7b ef 	mov    -0x10843000(,%edx,4),%edx
  802546:	f6 c2 01             	test   $0x1,%dl
  802549:	74 26                	je     802571 <pageref+0x3d>
		return 0;
	pte = vpt[VPN(v)];
  80254b:	c1 e8 0c             	shr    $0xc,%eax
  80254e:	8b 04 85 00 00 40 ef 	mov    -0x10c00000(,%eax,4),%eax
	if (!(pte & PTE_P))
  802555:	a8 01                	test   $0x1,%al
  802557:	74 18                	je     802571 <pageref+0x3d>
		return 0;
	return pages[PPN(pte)].pp_ref;
  802559:	c1 e8 0c             	shr    $0xc,%eax
  80255c:	8d 14 40             	lea    (%eax,%eax,2),%edx
  80255f:	c1 e2 02             	shl    $0x2,%edx
  802562:	b8 00 00 00 ef       	mov    $0xef000000,%eax
  802567:	0f b7 44 02 08       	movzwl 0x8(%edx,%eax,1),%eax
  80256c:	0f b7 c0             	movzwl %ax,%eax
  80256f:	eb 05                	jmp    802576 <pageref+0x42>
  802571:	b8 00 00 00 00       	mov    $0x0,%eax
}
  802576:	5d                   	pop    %ebp
  802577:	c3                   	ret    
	...

00802580 <__udivdi3>:
  802580:	55                   	push   %ebp
  802581:	89 e5                	mov    %esp,%ebp
  802583:	57                   	push   %edi
  802584:	56                   	push   %esi
  802585:	83 ec 10             	sub    $0x10,%esp
  802588:	8b 45 14             	mov    0x14(%ebp),%eax
  80258b:	8b 55 08             	mov    0x8(%ebp),%edx
  80258e:	8b 75 10             	mov    0x10(%ebp),%esi
  802591:	8b 7d 0c             	mov    0xc(%ebp),%edi
  802594:	85 c0                	test   %eax,%eax
  802596:	89 55 f0             	mov    %edx,-0x10(%ebp)
  802599:	75 35                	jne    8025d0 <__udivdi3+0x50>
  80259b:	39 fe                	cmp    %edi,%esi
  80259d:	77 61                	ja     802600 <__udivdi3+0x80>
  80259f:	85 f6                	test   %esi,%esi
  8025a1:	75 0b                	jne    8025ae <__udivdi3+0x2e>
  8025a3:	b8 01 00 00 00       	mov    $0x1,%eax
  8025a8:	31 d2                	xor    %edx,%edx
  8025aa:	f7 f6                	div    %esi
  8025ac:	89 c6                	mov    %eax,%esi
  8025ae:	8b 4d f0             	mov    -0x10(%ebp),%ecx
  8025b1:	31 d2                	xor    %edx,%edx
  8025b3:	89 f8                	mov    %edi,%eax
  8025b5:	f7 f6                	div    %esi
  8025b7:	89 c7                	mov    %eax,%edi
  8025b9:	89 c8                	mov    %ecx,%eax
  8025bb:	f7 f6                	div    %esi
  8025bd:	89 c1                	mov    %eax,%ecx
  8025bf:	89 fa                	mov    %edi,%edx
  8025c1:	89 c8                	mov    %ecx,%eax
  8025c3:	83 c4 10             	add    $0x10,%esp
  8025c6:	5e                   	pop    %esi
  8025c7:	5f                   	pop    %edi
  8025c8:	5d                   	pop    %ebp
  8025c9:	c3                   	ret    
  8025ca:	8d b6 00 00 00 00    	lea    0x0(%esi),%esi
  8025d0:	39 f8                	cmp    %edi,%eax
  8025d2:	77 1c                	ja     8025f0 <__udivdi3+0x70>
  8025d4:	0f bd d0             	bsr    %eax,%edx
  8025d7:	83 f2 1f             	xor    $0x1f,%edx
  8025da:	89 55 f4             	mov    %edx,-0xc(%ebp)
  8025dd:	75 39                	jne    802618 <__udivdi3+0x98>
  8025df:	3b 75 f0             	cmp    -0x10(%ebp),%esi
  8025e2:	0f 86 a0 00 00 00    	jbe    802688 <__udivdi3+0x108>
  8025e8:	39 f8                	cmp    %edi,%eax
  8025ea:	0f 82 98 00 00 00    	jb     802688 <__udivdi3+0x108>
  8025f0:	31 ff                	xor    %edi,%edi
  8025f2:	31 c9                	xor    %ecx,%ecx
  8025f4:	89 c8                	mov    %ecx,%eax
  8025f6:	89 fa                	mov    %edi,%edx
  8025f8:	83 c4 10             	add    $0x10,%esp
  8025fb:	5e                   	pop    %esi
  8025fc:	5f                   	pop    %edi
  8025fd:	5d                   	pop    %ebp
  8025fe:	c3                   	ret    
  8025ff:	90                   	nop
  802600:	89 d1                	mov    %edx,%ecx
  802602:	89 fa                	mov    %edi,%edx
  802604:	89 c8                	mov    %ecx,%eax
  802606:	31 ff                	xor    %edi,%edi
  802608:	f7 f6                	div    %esi
  80260a:	89 c1                	mov    %eax,%ecx
  80260c:	89 fa                	mov    %edi,%edx
  80260e:	89 c8                	mov    %ecx,%eax
  802610:	83 c4 10             	add    $0x10,%esp
  802613:	5e                   	pop    %esi
  802614:	5f                   	pop    %edi
  802615:	5d                   	pop    %ebp
  802616:	c3                   	ret    
  802617:	90                   	nop
  802618:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  80261c:	89 f2                	mov    %esi,%edx
  80261e:	d3 e0                	shl    %cl,%eax
  802620:	89 45 ec             	mov    %eax,-0x14(%ebp)
  802623:	b8 20 00 00 00       	mov    $0x20,%eax
  802628:	2b 45 f4             	sub    -0xc(%ebp),%eax
  80262b:	89 c1                	mov    %eax,%ecx
  80262d:	d3 ea                	shr    %cl,%edx
  80262f:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  802633:	0b 55 ec             	or     -0x14(%ebp),%edx
  802636:	d3 e6                	shl    %cl,%esi
  802638:	89 c1                	mov    %eax,%ecx
  80263a:	89 75 e8             	mov    %esi,-0x18(%ebp)
  80263d:	89 fe                	mov    %edi,%esi
  80263f:	d3 ee                	shr    %cl,%esi
  802641:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  802645:	89 55 ec             	mov    %edx,-0x14(%ebp)
  802648:	8b 55 f0             	mov    -0x10(%ebp),%edx
  80264b:	d3 e7                	shl    %cl,%edi
  80264d:	89 c1                	mov    %eax,%ecx
  80264f:	d3 ea                	shr    %cl,%edx
  802651:	09 d7                	or     %edx,%edi
  802653:	89 f2                	mov    %esi,%edx
  802655:	89 f8                	mov    %edi,%eax
  802657:	f7 75 ec             	divl   -0x14(%ebp)
  80265a:	89 d6                	mov    %edx,%esi
  80265c:	89 c7                	mov    %eax,%edi
  80265e:	f7 65 e8             	mull   -0x18(%ebp)
  802661:	39 d6                	cmp    %edx,%esi
  802663:	89 55 ec             	mov    %edx,-0x14(%ebp)
  802666:	72 30                	jb     802698 <__udivdi3+0x118>
  802668:	8b 55 f0             	mov    -0x10(%ebp),%edx
  80266b:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  80266f:	d3 e2                	shl    %cl,%edx
  802671:	39 c2                	cmp    %eax,%edx
  802673:	73 05                	jae    80267a <__udivdi3+0xfa>
  802675:	3b 75 ec             	cmp    -0x14(%ebp),%esi
  802678:	74 1e                	je     802698 <__udivdi3+0x118>
  80267a:	89 f9                	mov    %edi,%ecx
  80267c:	31 ff                	xor    %edi,%edi
  80267e:	e9 71 ff ff ff       	jmp    8025f4 <__udivdi3+0x74>
  802683:	90                   	nop
  802684:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802688:	31 ff                	xor    %edi,%edi
  80268a:	b9 01 00 00 00       	mov    $0x1,%ecx
  80268f:	e9 60 ff ff ff       	jmp    8025f4 <__udivdi3+0x74>
  802694:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802698:	8d 4f ff             	lea    -0x1(%edi),%ecx
  80269b:	31 ff                	xor    %edi,%edi
  80269d:	89 c8                	mov    %ecx,%eax
  80269f:	89 fa                	mov    %edi,%edx
  8026a1:	83 c4 10             	add    $0x10,%esp
  8026a4:	5e                   	pop    %esi
  8026a5:	5f                   	pop    %edi
  8026a6:	5d                   	pop    %ebp
  8026a7:	c3                   	ret    
	...

008026b0 <__umoddi3>:
  8026b0:	55                   	push   %ebp
  8026b1:	89 e5                	mov    %esp,%ebp
  8026b3:	57                   	push   %edi
  8026b4:	56                   	push   %esi
  8026b5:	83 ec 20             	sub    $0x20,%esp
  8026b8:	8b 55 14             	mov    0x14(%ebp),%edx
  8026bb:	8b 4d 08             	mov    0x8(%ebp),%ecx
  8026be:	8b 7d 10             	mov    0x10(%ebp),%edi
  8026c1:	8b 75 0c             	mov    0xc(%ebp),%esi
  8026c4:	85 d2                	test   %edx,%edx
  8026c6:	89 c8                	mov    %ecx,%eax
  8026c8:	89 4d f4             	mov    %ecx,-0xc(%ebp)
  8026cb:	75 13                	jne    8026e0 <__umoddi3+0x30>
  8026cd:	39 f7                	cmp    %esi,%edi
  8026cf:	76 3f                	jbe    802710 <__umoddi3+0x60>
  8026d1:	89 f2                	mov    %esi,%edx
  8026d3:	f7 f7                	div    %edi
  8026d5:	89 d0                	mov    %edx,%eax
  8026d7:	31 d2                	xor    %edx,%edx
  8026d9:	83 c4 20             	add    $0x20,%esp
  8026dc:	5e                   	pop    %esi
  8026dd:	5f                   	pop    %edi
  8026de:	5d                   	pop    %ebp
  8026df:	c3                   	ret    
  8026e0:	39 f2                	cmp    %esi,%edx
  8026e2:	77 4c                	ja     802730 <__umoddi3+0x80>
  8026e4:	0f bd ca             	bsr    %edx,%ecx
  8026e7:	83 f1 1f             	xor    $0x1f,%ecx
  8026ea:	89 4d f0             	mov    %ecx,-0x10(%ebp)
  8026ed:	75 51                	jne    802740 <__umoddi3+0x90>
  8026ef:	3b 7d f4             	cmp    -0xc(%ebp),%edi
  8026f2:	0f 87 e0 00 00 00    	ja     8027d8 <__umoddi3+0x128>
  8026f8:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8026fb:	29 f8                	sub    %edi,%eax
  8026fd:	19 d6                	sbb    %edx,%esi
  8026ff:	89 45 f4             	mov    %eax,-0xc(%ebp)
  802702:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802705:	89 f2                	mov    %esi,%edx
  802707:	83 c4 20             	add    $0x20,%esp
  80270a:	5e                   	pop    %esi
  80270b:	5f                   	pop    %edi
  80270c:	5d                   	pop    %ebp
  80270d:	c3                   	ret    
  80270e:	66 90                	xchg   %ax,%ax
  802710:	85 ff                	test   %edi,%edi
  802712:	75 0b                	jne    80271f <__umoddi3+0x6f>
  802714:	b8 01 00 00 00       	mov    $0x1,%eax
  802719:	31 d2                	xor    %edx,%edx
  80271b:	f7 f7                	div    %edi
  80271d:	89 c7                	mov    %eax,%edi
  80271f:	89 f0                	mov    %esi,%eax
  802721:	31 d2                	xor    %edx,%edx
  802723:	f7 f7                	div    %edi
  802725:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802728:	f7 f7                	div    %edi
  80272a:	eb a9                	jmp    8026d5 <__umoddi3+0x25>
  80272c:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802730:	89 c8                	mov    %ecx,%eax
  802732:	89 f2                	mov    %esi,%edx
  802734:	83 c4 20             	add    $0x20,%esp
  802737:	5e                   	pop    %esi
  802738:	5f                   	pop    %edi
  802739:	5d                   	pop    %ebp
  80273a:	c3                   	ret    
  80273b:	90                   	nop
  80273c:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802740:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802744:	d3 e2                	shl    %cl,%edx
  802746:	89 55 f4             	mov    %edx,-0xc(%ebp)
  802749:	ba 20 00 00 00       	mov    $0x20,%edx
  80274e:	2b 55 f0             	sub    -0x10(%ebp),%edx
  802751:	89 55 ec             	mov    %edx,-0x14(%ebp)
  802754:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802758:	89 fa                	mov    %edi,%edx
  80275a:	d3 ea                	shr    %cl,%edx
  80275c:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802760:	0b 55 f4             	or     -0xc(%ebp),%edx
  802763:	d3 e7                	shl    %cl,%edi
  802765:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802769:	89 55 f4             	mov    %edx,-0xc(%ebp)
  80276c:	89 f2                	mov    %esi,%edx
  80276e:	89 7d e8             	mov    %edi,-0x18(%ebp)
  802771:	89 c7                	mov    %eax,%edi
  802773:	d3 ea                	shr    %cl,%edx
  802775:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802779:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  80277c:	89 c2                	mov    %eax,%edx
  80277e:	d3 e6                	shl    %cl,%esi
  802780:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802784:	d3 ea                	shr    %cl,%edx
  802786:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  80278a:	09 d6                	or     %edx,%esi
  80278c:	89 f0                	mov    %esi,%eax
  80278e:	8b 75 e4             	mov    -0x1c(%ebp),%esi
  802791:	d3 e7                	shl    %cl,%edi
  802793:	89 f2                	mov    %esi,%edx
  802795:	f7 75 f4             	divl   -0xc(%ebp)
  802798:	89 d6                	mov    %edx,%esi
  80279a:	f7 65 e8             	mull   -0x18(%ebp)
  80279d:	39 d6                	cmp    %edx,%esi
  80279f:	72 2b                	jb     8027cc <__umoddi3+0x11c>
  8027a1:	39 c7                	cmp    %eax,%edi
  8027a3:	72 23                	jb     8027c8 <__umoddi3+0x118>
  8027a5:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  8027a9:	29 c7                	sub    %eax,%edi
  8027ab:	19 d6                	sbb    %edx,%esi
  8027ad:	89 f0                	mov    %esi,%eax
  8027af:	89 f2                	mov    %esi,%edx
  8027b1:	d3 ef                	shr    %cl,%edi
  8027b3:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  8027b7:	d3 e0                	shl    %cl,%eax
  8027b9:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  8027bd:	09 f8                	or     %edi,%eax
  8027bf:	d3 ea                	shr    %cl,%edx
  8027c1:	83 c4 20             	add    $0x20,%esp
  8027c4:	5e                   	pop    %esi
  8027c5:	5f                   	pop    %edi
  8027c6:	5d                   	pop    %ebp
  8027c7:	c3                   	ret    
  8027c8:	39 d6                	cmp    %edx,%esi
  8027ca:	75 d9                	jne    8027a5 <__umoddi3+0xf5>
  8027cc:	2b 45 e8             	sub    -0x18(%ebp),%eax
  8027cf:	1b 55 f4             	sbb    -0xc(%ebp),%edx
  8027d2:	eb d1                	jmp    8027a5 <__umoddi3+0xf5>
  8027d4:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  8027d8:	39 f2                	cmp    %esi,%edx
  8027da:	0f 82 18 ff ff ff    	jb     8026f8 <__umoddi3+0x48>
  8027e0:	e9 1d ff ff ff       	jmp    802702 <__umoddi3+0x52>
